home *** CD-ROM | disk | FTP | other *** search
/ c't freeware shareware 1997 / CT_SW_97.ISO / pc / software / betriebs / macos / frodo404.hqx / Frodo v4.0.4 / Commodore 64 Guide.TXT < prev    next >
Text File  |  1996-09-24  |  304KB  |  6,993 lines

  1. *********
  2.  
  3. Welcome to Project 64!
  4.  
  5. The goal of Project 64 is to preserve Commodore 64 related documents
  6. in electronic text format that might otherwise cease to exist with the
  7. rapid advancement of computer technology and declining interest in 8-
  8. bit computers on the part of the general population. If you would like
  9. to help by converting C64 related hardcopy documents to electronic
  10. texts please contact the manager of Project 64, Cris Berneburg, at
  11. 74171.2136@compuserve.com.
  12.  
  13. Extensive efforts were made to preserve the contents of the original
  14. document.  However, certain portions, such as diagrams, program
  15. listings, and indexes may have been either altered or sacrificed due
  16. to the limitations of plain vanilla text.  Diagrams may have been
  17. eliminated where ASCII-art was not feasible.  Program listings may be
  18. missing display codes where substitutions were not possible.  Tables
  19. of contents and indexes may have been changed from page number
  20. references to section number references. Please accept our apologies
  21. for these limitations, alterations, and possible omissions.
  22.  
  23. Document names are limited to the 8.3 file convention of DOS. The
  24. first characters of the file name are an abbreviation of the original
  25. document name. The version number of the etext follows next. After
  26. that a letter may appear to indicate the particular source of the
  27. document. Finally, the document is given a .TXT extension.
  28.  
  29. The author(s) of the original document and members of Project 64 make
  30. no representations about the accuracy or suitability of this material
  31. for any purpose.  This etext is provided "as-is".  Please refer to the
  32. warantee of the original document, if any, that may included in this
  33. etext.  No other warantees, express or implied, are made to you as to
  34. the etext or any medium it may be on.  Neither the author(s) nor the
  35. members of Project 64 will assume liability for damages either from
  36. the direct or indirect use of this etext or from the distribution of
  37. or modification to this etext.
  38.  
  39. *********
  40.  
  41. The Project 64 etext of the Commodore 64 User's Guide. Converted to
  42. etext by Frank Jeno Kontros <jeno@kontr.uzhgorod.ua>, the Non Stop
  43. Cracker.
  44.  
  45. C64USG10.TXT, September 1996, etext #91.
  46.  
  47. *********
  48.  
  49. Note: To extract the ascii text basic programs all at once from this
  50. etext use "tok64" by Cris Berneburg <74171.2136@compuserve.com>. Or to
  51. extract the uuencoded basic programs all at once use "uud" by Edwin
  52. Kremer <edwin@zlotty>.
  53.  
  54. *********
  55.  
  56.   There  was a great work,  but finally,  after 2 weeks of correcting and
  57. formatting  the  text to the format what you now see, it is ready. I hope
  58. that  this  manual  is  the  second  greatest project after COMMDODORE 64
  59. PROGRAMMER'S REFERENCE GUIDE.  It  is  dedicated to C64 users who haven't
  60. the original manual or buy 64 without it. Enjoy it!
  61.   Generally it is the original US manual with all programs  and  near all
  62. pictures.  There was many bugs & mispells corrected by me. Also the index
  63. now is more usable instead original.
  64.   If you find errors in the text,  please report them so that they can be
  65. fixed. There should not be many, though...
  66.  
  67. Frank Kontros, The Non Stop Cracker, jeno@kontr.uzhgorod.ua
  68.  
  69. *********
  70.  
  71. COMMODORE 64 USER'S GUIDE
  72.    _____
  73.   /  ___|___
  74.  |  /   |__/  c o m m o d o r e
  75.  |  \___|__\  C O M P U T E R
  76.   \_____|
  77.  
  78. USER'S MANUAL STATEMENT
  79.  
  80.   "This  equipment  generates  and  uses  radio  frequency  energy and if
  81. not  installed  and used properly, that is, in strict accordance with the
  82. manufacturer's   instructions,   may  cause  interference  to  radio  and
  83. television  reception.  It  has been type tested and found to comply with
  84. the  limits  for  a  Class  B  computing  device  in  accordance with the
  85. specifications  in  Subpart J of Part 15 of FCC rules, which are designed
  86. to   provide   reasonable   protection  against  such  interference  in a
  87. residential   installation.   However,   there   is   no  guarantee  that
  88. interference  will  not  occur  in  a  particular  installation.  If this
  89. equipment  does  cause  interference  to  radio  or television reception,
  90. which  can  be  determined  by turning the equipment off and on, the user
  91. is  encouraged  to  try to correct the interference by one or more of the
  92. following measures:
  93.  
  94.     - reorient the receiving antenna,
  95.  
  96.     - relocate the computer with respect to the receiver,
  97.  
  98.     - move the computer away from the receiver,
  99.  
  100.     - plug  the  computer  into  a  different outlet so that computer and
  101.       receiver are on different branch circuits.
  102.  
  103. "If  necessary,  the  user  should  consult  the dealer or an experienced
  104. radio/television  technician  for  additional  suggestions.  The user may
  105. find  the  following  booklet  prepared  by  the  Federal  Communications
  106. Commission  helpful:  'How  to Identify and Resolve Radio-TV Interference
  107. Problems.'  This  booklet  is available from the U.S. Government Printing
  108. Office, Washington, D.C. 20402, Stock No. 004-000-00345-4."
  109.  
  110.  
  111. COMMODORE 64 USER'S GUIDE
  112.  
  113. Published by
  114. Commodore Business Machines, Inc.
  115. and
  116. Howard W. Sams & Co., Inc.
  117.  
  118.  
  119. FIRST EDITION
  120. THIRD PRINTING-1983
  121.  
  122. Copyright (C) 1982 by Commodore Business Machines, Inc.
  123. All rights reserved.
  124.  
  125. This manual is copyrighted and contains proprietary information.  No part
  126. of this publication may be reproduced,  stored in a retrieval system,  or
  127. transmitted  in  any  form  or  by  any  means,  electronic,  mechanical,
  128. photocopying,   recording,   or  otherwise,  without  the  prior  written
  129. permission of COMMODORE BUSINESS MACHINES, Inc.
  130.  
  131.  
  132. TABLE OF CONTENTS
  133.  
  134. INTRODUCTION
  135.  
  136. 1. SETUP
  137.    1.1. Unpacking and Connecting the Commodore 64
  138.    1.2. Installation
  139.    1.3. Optional Connections
  140.    1.4. Operation
  141.    1.5. Color Adjustment
  142.  
  143. 2. GETTING STARTED
  144.    2.1. Keyboard
  145.    2.2. Back to Normal
  146.    2.3. Loading and Saving Programs
  147.    2.4. PRINT and Calculations
  148.    2.5. Precedence
  149.    2.6. Combining Things
  150.  
  151. 3. BEGINNING BASIC PROGRAMMING
  152.    3.1. The Next Step
  153.         GOTO
  154.    3.2. Editing Tips
  155.    3.3. Variables
  156.    3.4. IF ... THEN
  157.    3.5. FOR ... NEXT Loops
  158.  
  159. 4. ADVANCED BASIC
  160.    4.1. Introduction
  161.    4.2. Simple Animation
  162.         Nested Loops
  163.    4.3. INPUT
  164.    4.4. GET
  165.    4.5. Random Numbers and Other Functions
  166.    4.6. Guessing Game
  167.    4.7. Your Roll
  168.    4.8. Random Graphics
  169.         CHR$ and ASC Functions
  170.  
  171. 5. ADVANCED COLOR AND GRAPHIC COMMANDS
  172.    5.1. Color and Graphics
  173.    5.2. PRINTing Colors
  174.    5.3. Color CHR$ Codes
  175.    5.4. PEEKs and POKEs
  176.    5.5. Screen Graphics
  177.    5.6. Screen Memory Map
  178.    5.7. Color Memory Map
  179.    5.8. More Bouncing Balls
  180.  
  181. 6. SPRITE GRAPHICS
  182.    6.1. Introduction to Sprites
  183.    6.2. Sprite Creation
  184.    6.3. Additional Notes on Sprites
  185.    6.4. Binary Arithmetic
  186.  
  187. 7. CREATING SOUND
  188.    7.1. Using Sound if You're Not a Computer Programmer
  189.    7.2. Structure of a Sound Program
  190.    7.3. Sample Sound Program
  191.    7.4. Making Music on Your Commodore 64
  192.    7.5. Important Sound Settings
  193.    7.6. Playing a Song on the Commodore 64
  194.    7.7. Creating Sound Effects
  195.    7.8. Sample Sound Effects To Try
  196.  
  197. 8. ADVANCED DATA HANDLING
  198.    8.1. READ and DATA
  199.    8.2. Averages
  200.    8.3. Subscripted Variables
  201.         One-Dimensional Arrays
  202.         Averages Revisited
  203.    8.4. DIMENSION
  204.    8.5. Simulated Dice Roll With Arrays
  205.    8.6. Two-Dimensional Arrays
  206.  
  207. APPENDICES
  208.    Introduction
  209.    A: COMMODORE 64 ACCESSORIES AND SOFTWARE
  210.    B: ADVANCED CASSETTE OPERATION
  211.    C: COMMODORE 64 BASIC
  212.    D: ABBREVIATIONS FOR BASIC KEYWORDS
  213.    E: SCREEN DISPLAY CODES
  214.    F: ASCII AND CHR$ CODES
  215.    G: SCREEN AND COLOR MEMORY MAP
  216.    H: DERIVING MATHEMATICAL FUNCTIONS
  217.    I: PINOUTS FOR INPUT/OUTPUT DEVICES
  218.    J: PROGRAMS TO TRY
  219.    K: CONVERTING STANDARD BASIC PROGRAMS TO COMMODORE 64 BASIC
  220.    L: ERROR MESSAGES
  221.    M: MUSIC NOTE VALUES
  222.    N: BIBLIOGRAPHY
  223.    O: SPRITE REGISTER MAP
  224.    P: COMMODORE 64 SOUND CONTROL SETTINGS
  225.  
  226. INDEX
  227.  
  228.  
  229.  
  230. INTRODUCTION
  231.  
  232.   Congratulations,  on  your purchase of one of the best computers in the
  233. world.  You  are  now  the proud owner of the COMMODORE 64.  Commodore is
  234. known  as  The  Friendly Computer company,  and part of being friendly is
  235. giving  you easy to read,  easy to use and easy to understand instruction
  236. manuals.  The  COMMODORE 64 USER'S GUIDE  is designed to give you all the
  237. information  you  need to properly set up your equipment,  get acquainted
  238. with  operating  the  COMMODORE 64,  and give you a simple,  fun start at
  239. learning to make your own program.
  240.   For  those  of  you  who  don't want to bother learning how to program,
  241. we've put all the information you need to use Commodore programs or other
  242. prepackaged programs and/or game cartridges  (third party software) right
  243. up  front.  This means  you don't have to hunt through the entire book to
  244. get started.
  245.   Now  let's  look at some of the exciting features that are just waiting
  246. for you inside your COMMODORE 64. First, when it comes to graphics you've
  247. got  the  most  advanced  picture maker in the microcomputer industry. We
  248. call it SPRITE GRAPHICS, and it allows you to design your own pictures in
  249. 4  different  colors,  just  like  the  ones you see on arcade type video
  250. games.  Not only that,  the  SPRITE EDITOR let's you animate as many as 8
  251. different  picture  levels  at  one time.  The SPRITE EDITOR will soon be
  252. available  as  software  program  that  you  can  load directly into your
  253. COMMODORE 64.  You  can  move your creations anywhere on the screen, even
  254. pass  one  image  in  front of or behind another.  Your COMMODORE 64 even
  255. provides  automatic  collision  detection which instructs the computer to
  256. take the action you want when the sprites hit each other.
  257.   Next,  the COMMODORE 64 has built-in music and sound effects that rival
  258. many well known music synthesizers.  This part of your computer gives you
  259. 3  independent voices,  each with a full 9 octave "piano-type" range.  In
  260. addition  you  get  4 different waveforms (sawtooth,  triangle,  variable
  261. pulse, and noise),  a programmable ADSR (attack, decay, sustain, release)
  262. envelope generator and a programmable high,  low, and bandpass filter for
  263. the voices, and variable resonance and volume controls.  If you want your
  264. music to play back with professional sound reproduction, the COMMODORE 64
  265. allows  you  to  connect  your  audio  output  to almost any high-quality
  266. amplification system.
  267.   While  we're  on  the  subject  of connecting the COMMODORE 64 to other
  268. pieces   of   equipment  ...  your  system  can  be  expanded  by  adding
  269. accessories, known as peripherals, as your computing needs grow.  Some of
  270. your  options  include  items like a DATASSETTE recorder or as many as 5,
  271. VIC  1541  disk drive units for the programs you make and/or play. If you
  272. already have a VIC 1540 disk drive your dealer can update it for use with
  273. the  COMMODORE 64.  You  can  add  a  VIC  dot matrix printer to give you
  274. printed copies of your programs, letters, invoices, etc... If you want to
  275. connect  up  with larger computers and their massive data bases then just
  276. plug  in  a  VICMODEM  cartridge,  and  get  the  services of hundreds of
  277. specialists  and  a  variety of information networks through your home or
  278. business telephone.  Finally  if you're one of those people interested in
  279. the  wide  variety   of  applications  software  available  in  CP/M, the
  280. COMMODORE 64 can be fitted with a plug-in Z-80 microprocessor.
  281.   Just  as  important as all the available hardware is the fact that this
  282. USER'S GUIDE  will  help  you develop your understanding of computers. It
  283. won't  tell  you  everything  there  is  to know about computers,  but it
  284. will  refer  you  to  a  wide  variety  of publications for more detailed
  285. information  about  the  topics presented.  Commodore wants you to really
  286. enjoy your new COMMODORE 64.  And to have fun,  remember:  programming is
  287. not  the  kind of thing you can learn in a day.  Be patient with yourself
  288. as  you  go  through the USER'S GUIDE.  But before you start,  take a few
  289. minutes  to  fill  out  and mail in the owner/registration card that come
  290. with  your  computer.  It  will ensure that your COMMODORE 64 is properly
  291. registered  with  Commodore  Headquarters  and  that you receive the most
  292. up-to-date  information  regarding  future enhancements for your machine.
  293. Welcome to a whole new world of fun!
  294.  
  295. NOTE:
  296.   Many  programs  are  under  development  while  this  manual  is  being
  297. produced.  Please  check  with  your  local  Commodore  dealer  and  with
  298. Commodore User's Magazines  and Clubs,  which will keep you up to date on
  299. the  wealth  of applications programs being written for the Commodore 64,
  300. worldwide.
  301.  
  302.  
  303.  
  304. 1. SETUP
  305.  
  306.  
  307. 1.1. Unpacking and Connecting the Commodore 64
  308.  
  309.   The  following  step-by-step  instructions  show you how to connect the
  310. Commodore 64  to your television set,  sound system,  or monitor and make
  311. sure everything is working properly.
  312.   Before  attaching  anything to the computer,  check the contents of the
  313. Commodore  64  container.  Besides  this  manual,  you  should  find  the
  314. following items:
  315.  
  316.   1. Commodore 64
  317.   2. Power supply (black box with an AC plug and supply cord)
  318.   3. Video cable
  319.   4. TV Switchbox (small silver box with short antenna leads).
  320.  
  321.   If any items are missing  check back with your dealer immediately for a
  322. replacement.
  323.   First,  let's take a look at the arrangement of the various connections
  324. on the computer and how each functions.
  325.  
  326.  
  327.                                     /####\--------^--\
  328.                                /####                 |
  329.                           /####                      |
  330.                  ____/####                           |
  331.                 /                                    |
  332.                |               ----   ----  __  /-\  |
  333.                |               \--/   \--/  ==  \_/  |
  334.                 \________________\___/______/____|__/
  335.                                   \/       /     |
  336.                                   3       2      1
  337.                                  GAME   POWER  POWER
  338.                                 PORTS  SWITCH  SOCKET
  339.  
  340.  
  341.      ___/###\__/##_##_##_##_##_##_##_##_##_##_##_##_##_##_##_##\__
  342.     |-------------------------------------------------------------|
  343.     |                                                             |
  344.     |                                                             |
  345.     |                                                             |
  346.     | +--------------+            /-\  /-\  +------+ +----------+ |
  347.     | |==============|  [=]  O    \_/  \_/  |======| |==========| |
  348.     +-----/-------------/----/-----\-----\--------\---------\-----+
  349.        /              /     /       \      \        \         \
  350.      4              5      6         7       8        9         10
  351.    CARTRIDGE  CHANNEL     TV     AUDIO/VIDEO  SERIAL  CASSETTE  USER
  352.      SLOT    SELECTOR  CONNECTOR  CONNECTOR    PORT  INTERFACE  PORT
  353.  
  354.  
  355. SIDE PANEL CONNECTIONS
  356.  
  357.   1. POWER SOCKET.  The  free  end  of the cable from the power supply is
  358.      attached here to supply power to the Commodore 64.
  359.   2. POWER SWITCH. Turns on power to the Commodore 64.
  360.   3. GAME PORTS.  Each  game  connector  can  accept  a  joystick or game
  361.      controller  paddle,  while the lightpen can only be plugged into the
  362.      game port closest to the front of your computer.
  363.  
  364. REAR CONNECTIONS
  365.  
  366.   4. CARTRIDGE SLOT.  The rectangular slot to the left accepts program or
  367.      game cartridges.
  368.   5. CHANNEL SELECTOR.  Use  this  switch  to select which TV channel the
  369.      computer's picture will be displayed on.
  370.   6. TV CONNECTOR.  This connector supplies both the picture and sound to
  371.      your television set.
  372.   7. AUDIO & VIDEO OUTPUT.  This  connector supplies direct audio,  which
  373.      can  be connected to a high quality sound system,  and a "composite"
  374.      video signal, which can be fed into a television "monitor".
  375.   8. SERIAL PORT.  You can attach a printer or single disk drive directly
  376.      to the Commodore 64 through this connector.
  377.   9. CASSETTE INTERFACE.  A  DATASSETTE  recorder  can be attached to the
  378.      computer  so  you  can  save  information entered for use at a later
  379.      time.
  380.  10. USER PORT.  Various interface cartridges can be attached to the user
  381.      port, such as the VICMODEM, or RS 232 communication cartridge.
  382.  
  383.  
  384. 1.2. Installation
  385.  
  386.  
  387. CONNECTIONS TO YOUR TV
  388.  
  389. Connect the computer to your TV as shown below.
  390.  
  391.  
  392.                                       TV
  393.                                    Switchbox   +--+-----------------+--+
  394.                                     +-----+    |  | /-------------\#|  |
  395.                 /---------------#= =|     |=   |  | |             |#|  |
  396.                 |                   +--#--+    |  | |             |#|  |
  397.                 |                      \\_     |  | |             | |  |
  398.                 |                       \_     |  | |             | |  |
  399.          To TV  |                  To 300 Ohm  |  | \-------------/ |  |
  400.          Signal #                Antenna Input +==+=================+==+
  401.           Jack  |
  402.   /------------------------\
  403.  |                          |=---\
  404.  | ####################  ## |    |
  405.  | ####################  ## |    |
  406.  |  ##################   ## |    |
  407.  |    ##############     ## |    |
  408.   \________________________/     |
  409.                                  |
  410.                                  |
  411.                                  |
  412.                                +---+
  413.                                |   | Power
  414.                                |   | Supply
  415.                                +---+
  416.                                  |
  417.                                  |
  418.  
  419.  
  420. 1. Attach one end of the TV cable to the phono type TV signal jack at the
  421.    rear of the Commodore 64. Just push it in. Either end of the cable can
  422.    be used.
  423. 2. Connect the other end of the cable to the antenna switchbox. Just push
  424.    it in.
  425. 3. If you have a VHF antenna, disconnect it from your TV set.
  426. 4. Connect your VHF antenna cable to the screw terminals labeled "antenna
  427.    input"  on  the  switchbox.  If your antenna cable is the round 75-ohm
  428.    coax  type,  use  a 75-ohm to 300-ohm adapter (not supplied) to attach
  429.    your antenna cable to the switchbox.
  430. 5. Connect the twin lead output cable of the antenna switchbox to the VHF
  431.    antenna  terminals  of  your  TV set.  If your set is one of the newer
  432.    types  with  a round 75-ohm VHF connector,  you will need a 300-ohm to
  433.    75-ohm converter (not supplied) to connect the switchbox to the 75-ohm
  434.    VHF antenna input on the set.
  435. 6. Set  the  TV's  VHF  tuner  to  the  channel  number  indicated on the
  436.    computer's  channel selector switch (channel 3  move the switch to the
  437.    left,  channel 4  move the switch to the right).  If a strong local TV
  438.    signal  is present on one of these channels,  select the other channel
  439.    to avoid possible interference.
  440. 7. Plug  the  power supply cable into the power socket on the side of the
  441.    Commodore 64.  Just  push  it in.  It is "keyed" to allow insertion in
  442.    only one direction, so you can't connect the power cord the wrong way.
  443.    The power supply converts household current into the form the computer
  444.    uses.
  445.  
  446.  
  447.                             /+---------------+
  448.                            + |               |
  449.                            | |       |       |
  450.                            | |       |       |
  451.                      /     | |       |       |
  452.                     |========|       |       |
  453.                     |========|       |       |
  454.                    /       | |       |       |
  455.                            | |               |
  456.                            | |    _     _    /
  457.                            | |   |O|   |O|  |
  458.                            + |    #     #   |
  459.                             \+-----\---/----+
  460.                                     \ /
  461.                                     | |
  462.                                     | |
  463.                                     | |
  464.                                    ++-++
  465.                    75 Ohm to       |___|
  466.                     300 Ohm  ----> |   |
  467.                     Adapter        |   |
  468.                                    +---+
  469.                                     \=/
  470.                                     ###
  471.                  Your 75 Ohm ---->  | |
  472.               Coax VHF Antenna      | |
  473.  
  474.  
  475.  
  476.                        /-----------    -----------\
  477.                       |  /==\      /==\      /==\  |
  478.                       | ||__||    ||__||    ||__|| |
  479.                       |  \__/      \__/      \__/  |
  480.                        \__________________________/
  481.                                                ^    To VHF
  482.                                               _|___  ANT.
  483.                                              +---+/
  484.                                 300 Ohm      |   ||
  485.                                to 75 Ohm --> |   ||
  486.                                 Adapter      ++-++/
  487.                                               | |
  488.                                               | |
  489.                                               |_|/
  490.                                              /
  491.  
  492.  
  493.   The Commodore 64 is now correctly connected.  No additional connections
  494. are required to use the computer with your TV. The antenna switchbox will
  495. connect the computer to the TV when the slide switch is in the "computer"
  496. position.  When  the switch is in the "TV" position your set will operate
  497. normally.
  498.  
  499.  
  500.      ___/###\__/##_##_##_##_##_##_##_##_##_##_##_##_##_##_##_##\__
  501.     |-------------------------------------------------------------|
  502.     |                                                             |
  503.     |                                                             |
  504.     |                                                             |
  505.     | +--------------+            /-\  /-\  +------+ +----------+ |
  506.     | |==============|  [=]  O    \_/  \_/  |======| |==========| |
  507.     +-------------------------------------------------------------+
  508.                              ^
  509.                    To        |
  510.                 TV Signal    |
  511.                   Jack
  512.                              |                  Back of Your TV
  513.                              #         _/-----------------------------
  514.                             | |       /
  515.                             \ /      +--------------------------------
  516.                              |          |
  517.                              \__________I______________________
  518.                                         |                      \
  519.                                         |-------+               |
  520.                                         |  UHF  |               |
  521.                                         | O   O |              |#|
  522.                                         |  VHF  |               |
  523.                                         ||O| |O||     /---------=-\
  524.                                        /| #   # |    |  COMPUTER   |
  525.                                      /  |-|---|-+    |      |      |
  526.                                200 Ohm  | |   |      |      |      |
  527.                                  VHF    | |    \_____|      |      |
  528.                                 Input   |  \_________|      |      |
  529.                                         |            |      |      |
  530.                                         |            |     TV      |
  531.                                         |  Antenna ->|   |O| |O|   |
  532.                                         |  Switch     \___#___#___/
  533.                                         |    Box          |   | __
  534.                                         |                 |___|/
  535.                                                         __/
  536.                                                         Your VHF
  537.                                                          Antenna
  538.                                                         (If Used)
  539.  
  540.  
  541. 1.3. Optional Connections
  542.  
  543.   Since the Commodore 64 furnishes a channel of high fidelity sound,  you
  544. may wish to play it through a quality amplifier to realize the best sound
  545. possible.   In addition,  the  Commodore  64  also  provides  a  standard
  546. "composite" video signal, which can be fed into a television monitor.
  547.   These  options  are made possible by the audio/video output jack on the
  548. rear panel  of the Commodore 64.  The easiest way to gain access to these
  549. signals is by using a standard 5-Pin DIN audio cable (not supplied). This
  550. cable connects directly to the audio/video connector on the computer. Two
  551. of  the  four pins on the opposite end of the cable contain the audio and
  552. video signals.  Optionally,  you can construct your own cable,  using the
  553. pinouts shown in Appendix I as a guide.
  554.   Normally,  the  BLACK  connector  of  the  DIN cable supplies the AUDIO
  555. signal.  This  plug  may  be  connected  to  the  AUXILIARY  input  of an
  556. amplifier,  or the AUDIO IN connector of a monitor or other video system,
  557. such as a video cassette recorder (VCR).
  558.   The  WHITE  or  RED connector usually supplies the direct VIDEO signal.
  559. This  plug is connected to the VIDEO IN connector of the monitor or video
  560. input section of some other video system, such as a VCR.
  561.   Depending  on  the manufacturer of your DIN cable,  the color coding of
  562. the plugs may be different.  Use the pinouts shown in Appendix I to match
  563. up the proper plugs  if you don't get an audio or video signal  using the
  564. suggested connections.
  565.  
  566.  
  567.  
  568.                    __###__################################__
  569.                   /                                         \
  570.                   |               Audio/Video               |
  571.                   |                 Output                  |
  572.                   |-----------------_---_-------------------|
  573.                   | =========  = o | | | |  ===== ========= |
  574.                   +-----------------------------------------+
  575.  
  576.                                     ^
  577.                                     |
  578.  
  579.                                    /-\
  580.                                    | |
  581.                                    | |
  582.                                     #
  583.                                     |
  584.                                     |
  585.                        To AUXILIARY |
  586.                          INPUT or   |
  587.          ____________  TUNER INPUT  |
  588.         /            \             / \  To VIDEO IN
  589.   +----++------------++----+  <-#-/   \-#->  +------------+---+
  590.   |    || ### ====== ||    |                 | /--------\ | O |
  591.   |    || ===  OoooO ||    |                 ||          || = |
  592.   |    ||------------||    |                 ||          || o |
  593.   |    ||  |   |   | ||    |                 | \________/ |   |
  594.   |    ||  |   |   | ||    |                 +------------+---+
  595.   +----++============++----+
  596.                                                  TV Monitor
  597.          Audio System
  598.  
  599.  
  600.   If you purchased peripheral equipment, such as a VIC 1541 disk drive or
  601. a VIC 1525E printer,  you may wish to connect it at this time.  Refer  to
  602. the  user's  manuals  supplied  with  any  additional  equipment  for the
  603. procedure for connecting it to the computer.
  604.  
  605.   A completed system might look like this.
  606.  
  607. [ Picture omitted ]
  608.  
  609.  
  610. 1.4. Operation
  611.  
  612. USING THE COMMODORE 64
  613.  
  614. 1. Turn  on  the computer using the rocker switch on the right-side panel
  615.    when you're looking at the computer from the front.
  616. 2. After a few moments the following will be displayed on the TV screen:
  617.  
  618.       **** COMMODORE 64 BASIC V2 ****
  619.    64K RAM SYSTEM  38911 BASIC BYTES FREE
  620.  
  621.    READY.
  622.    _  <----------- Cursor signals Commodore 64 is waiting for your input
  623.  
  624. 3. If your TV has a manual fine tuning knob,  adjust the TV until you get
  625.    a clear picture.
  626. 4. You  may also want to adjust the color and tint controls on the TV for
  627.    the best display. You can use the color adjustment procedure described
  628.    later to get everything setup properly.  When you first get a picture,
  629.    the  screen  should appear mostly dark blue,  with a light blue border
  630.    and letters.
  631.  
  632.   If  you  don't  get  the  expected  results,  recheck  the  cables  and
  633. connections. The accompanying chart will help you isolate any problem.
  634.  
  635.  
  636. TROUBLESHOOTING CHART
  637.  
  638. +-----------------------------------------------------------------------+
  639. | Symptom               Cause                 Remedy                    |
  640. +-----------------------------------------------------------------------+
  641. | Indicator Light      Computer not "On"     Make sure power switch     |
  642. | not "On"                                   is in "On" position        |
  643. |                                                                       |
  644. |                      Power cable not       Check power socket for     |
  645. |                      not plugged in        loose or disconnected      |
  646. |                                            power cable                |
  647. |                                                                       |
  648. |                      Power supply not      Check connection with      |
  649. |                      plugged in            wall outlet                |
  650. |                                                                       |
  651. |                      Bad fuse in           Take system to authorized  |
  652. |                      computer              dealer for replacement of  |
  653. |                                            fuse                       |
  654. |                                                                       |
  655. |                      TV on wrong           Check other channel        |
  656. |                      channel               for picture (3 or 4)       |
  657. |                                                                       |
  658. |                      Incorrect             Computer hooks up to       |
  659. |                      hookup                VHF antenna terminals      |
  660. |                                                                       |
  661. |                      Video cable not       Check TV output cable      |
  662. |                      plugged in            connection                 |
  663. |                                                                       |
  664. |                      Computer set for      Set computer for same      |
  665. |                      wrong channel         channel as TV (3 or 4)     |
  666. |                                                                       |
  667. | Random patterns on   Cartridge not         Reinsert cartridge after   |
  668. | TV with cartridge    properly inserted     turning off power          |
  669. | in place                                                              |
  670. |                                                                       |
  671. | Picture without      Poorly tuned TV       Retune TV                  |
  672. | color                                                                 |
  673. |                                                                       |
  674. | Picture with         Bad color             Adjust color/hue/          |
  675. | poor color           adjustment on TV      brightness controls on TV  |
  676. |                                                                       |
  677. | Sound with excess    TV volume up high     Adjust volume of TV        |
  678. | background noise                                                      |
  679. |                                                                       |
  680. | Picture OK,          TV volume too low     Adjust volume of TV        |
  681. | but no sound                                                          |
  682. |                                                                       |
  683. |                      Aux. output not       Connect sound jack to      |
  684. |                      properly connected    aux. input on amplifier    |
  685. |                                            and select aux. input      |
  686. +-----------------------------------------------------------------------+
  687.  
  688. TIP:  The  COMMODORE 64  was designed  to be used by everyone.  But we at
  689. Commodore  recognize  that  computer  users may,  occasionally,  run into
  690. difficulties.  To  help  answer  your  questions  and  give  you some fun
  691. programming  ideas,  Commodore  has  created several publications to help
  692. you.  You might also find that it's a good idea to join a Commodore Users
  693. Club  to  help  you  meet some other COMMODORE 64 owners who can help you
  694. gain knowledge and experience.
  695.  
  696. CURSOR
  697.  
  698.   The  flashing  square  under  READY  is called the cursor and indicates
  699. where what you type on the keyboard  will be displayed on the screen.  As
  700. you  type,  the cursor will move ahead one space,  as the original cursor
  701. position  is  replaced  with  the character you typed.  Try typing on the
  702. keyboard and watch as characters you type are displayed on the TV screen.
  703.  
  704.  
  705. 1.5. Color Adjustment
  706.  
  707.   There  is  a simple way to get a pattern of colors on the TV so you can
  708. easily  adjust  the  set.  Even  though  you may not be familiar with the
  709. operation  of the computer right now,  just follow along,  and you'll see
  710. how easy it is to use the Commodore 64.
  711.   First,  look on the left side of the keyboard and locate the key marked
  712. <CTRL>.  This  stands for ConTRoL and is used,  in conjunction with other
  713. keys, to instruct the computer to do a specific task.
  714.  
  715. [ Picture omitted ]
  716.  
  717.   To  use  a  control  function,  you  hold  down  the  <CTRL>  key while
  718. depressing a second key.
  719.   Try this:  hold the <CTRL> key  while also depressing the <9> key. Then
  720. release both keys. Nothing obvious should have happened, but if you touch
  721. any  key  now,  the  screen  will show the character displayed in reverse
  722. type, rather than normal type -- like the opening message or anything you
  723. typed earlier.
  724.   Hold down the <SPACE BAR>. What happens? If you did the above procedure
  725. correctly,  you  should  see  a light blue bar move across the screen and
  726. then move down to the next line as long as the <SPACE BAR> is depressed.
  727.  
  728.      **** COMMODORE 64 BASIC V2 ****
  729.   64K RAM SYSTEM  38911 BASIC BYTES FREE
  730.  
  731.   READY.
  732.   ____________________________
  733.   __________
  734.  
  735.   Now,  hold <CTRL>  while depressing any of the other number keys.  Each
  736. of  them  has a color  marked on the front.  Anything displayed from this
  737. point will be in that color. For example, hold <CTRL> and the <8> key and
  738. release both. Now hold the <SPACE BAR>.
  739.   Watch the display.  The bar is now in yellow!  In a like manner you can
  740. change  the  bar  to  any  of  the colors indicated on the number keys by
  741. holding <CTRL> and the appropriate key.
  742.   Change the bar to a few more different colors and then adjust the color
  743. and  tint  controls  on  your  TV  so  the display matches the colors you
  744. selected.
  745.   The display should appear something like this:
  746.  
  747.      **** COMMODORE 64 BASIC V2 ****
  748.   64K RAM SYSTEM  38911 BASIC BYTES FREE
  749.  
  750.   READY.
  751.   _________________________     <------ <3> Red bar
  752.   _______ ____________ ____     <------ <3>,<6>,<7> Red, Green, Blue bars
  753.   __________ ______________     <------ <7>,<8> Blue, Yellow bars
  754.   ____________                  <------ <8> Yellow bar
  755.  
  756.   At  this  point  everything is properly adjusted and working correctly.
  757. The following chapters will introduce you to the BASIC language. However,
  758. you can  immediately start using some of the many prewritten applications
  759. and  games available for the Commodore 64  without knowing anything about
  760. computer programming.
  761.   Each  of  these packages contains detailed information about how to use
  762. the  program.  It is suggested,  though,  that you read through the first
  763. few  chapters  of  this  manual  to  become  more familiar with the basic
  764. operation of your new system.
  765.  
  766.  
  767.  
  768. 2. GETTING STARTED
  769.  
  770.  
  771. 2.1. Keyboard
  772.  
  773.   Now that you've got everything set up and adjusted,  please  take a few
  774. moments  to  familiarize  yourself  with  the keyboard which is your most
  775. important means of communication with the Commodore 64.
  776.   You  will  find  the keyboard similar to a standard typewriter keyboard
  777. found  in  most  areas.  There  are,  however, a number of new keys which
  778. control specialized functions. What follows is a brief description of the
  779. various  keys  and how they function.  The detailed operation of each key
  780. will be covered in later sections.
  781.  
  782. [ Picture omitted ]
  783.  
  784.  
  785. <RETURN>
  786.  
  787.   The <RETURN> key signals the computer  to look at the information  that
  788. you typed and enters that information into memory.
  789.  
  790.  
  791. <SHIFT>
  792.  
  793.   The <SHIFT> key works like that on a standard typewriter. Many keys are
  794. capable of displaying two letters or symbols  and two graphic characters.
  795. In  the  "upper/lower case" mode the <SHIFT> key gives you standard upper
  796. case  characters.  In the "upper case/graphic" mode  the <SHIFT> key will
  797. display the graphic character on the right hand side of the front part of
  798. the key.
  799.   In the case of special YELLOW function keys,  the <SHIFT> key will give
  800. you the function marked on the front of the key.
  801.  
  802.  
  803. EDITING
  804.  
  805.   No  one  is  perfect,  and  the Commodore 64 takes that into account. A
  806. number  of  editing  keys  let  you  correct  typing  mistakes  and  move
  807. information around on the screen.
  808.  
  809.  
  810. <CRSR>
  811.  
  812.   There are two keys marked <CRSR> (CuRSoR), one with up and down arrows,
  813. the other with left and right arrows.  You can use these keys to move the
  814. cursor up and down or left and right.  In the unshifted mode,  the <CRSR>
  815. keys  will  let  you  move  the  cursor down and to the right.  Using the
  816. <SHIFT> key and <CRSR> keys allows the cursor to be moved either up or to
  817. the  left.  The  cursor keys have a special repeat feature that keeps the
  818. cursor moving until you release the key.
  819.  
  820.  
  821. <INST/DEL>
  822.  
  823.   If  you  hit  the  <INST/DEL>  key,  the cursor will move back a space,
  824. erasing  (DELeting)  the  previous  character you typed. If you're in the
  825. middle of a line, the character to the left is deleted and the characters
  826. to the right automatically move together to close up the space.
  827.   A <SHIFT>ed <INST/DEL> allows you to INSerT information on a line.  For
  828. example,  if you noticed a typing mistake  in the beginning of a line  --
  829. perhaps you left out part of the name  -- you could use the <CRSR> key to
  830. move back to the error  and then hit <INST/DEL>  to insert a space.  Then
  831. just type in the missing later.
  832.  
  833.  
  834. <CLR/HOME>
  835.  
  836.   <CLR/HOME>  positions  the cursor at the "HOME" position of the screen,
  837. which is the upper left-hand corner.  A shifted <CLR/HOME> will clear the
  838. screen and place the cursor in the home position.
  839.  
  840.  
  841. <RESTORE>
  842.  
  843.   <RESTORE>  operates as the name implies.  It stores the computer to the
  844. normal  state  it was in before you changed things with a program or some
  845. command. A lot more will be said on this in later chapters.
  846.  
  847.  
  848. FUNCTION KEYS
  849.  
  850.   The  four  function  keys  on  the  right  side  of the keyboard can be
  851. "programmed"  to  handle  a variety of functions.  They can be defined in
  852. many ways to handle repetitive tasks.
  853.  
  854. [ Picture omitted ]
  855.  
  856.  
  857. <CTRL>
  858.  
  859.   The  <CTRL>  key,  which  stands for ConTRoL, allows you to set colors,
  860. and  perform  other  specialized  functions. You hold the <CTRL> key down
  861. while  depressing  another  designated key to get a control function. You
  862. had an opportunity to try the <CTRL> key  when you changed text colors to
  863. create different color bars during the setup procedure.
  864.  
  865.  
  866. <RUN/STOP>
  867.  
  868.   Normally,  depressing the <RUN/STOP>  key  will stop the execution of a
  869. BASIC program. It signals the computer to STOP doing something. Using the
  870. <RUN/STOP> key in the shifted mode will allow you to automatically load a
  871. program from tape.
  872.  
  873.  
  874. <C=> COMMODORE KEY
  875.  
  876.   The Commodore key <C=> performs a number of functions. First, it allows
  877. you to move between the text and graphic display modes.
  878.   When  the computer is first turned on,  it is in the upper case/graphic
  879. mode,  that  is,  everything  you  type is in upper case letters.  As was
  880. mentioned, using the <SHIFT> key in this mode will display the graphic on
  881. the right side of the keys.
  882.   If you hold down the <C=> key and <SHIFT> key,  the display will change
  883. to upper and lower case. Now, if you hold down the <C=> key and any other
  884. key with a graphic symbol,  the graphic shown on the left side of the key
  885. will be displayed.
  886.   To get back into the upper case/graphic mode hold down the <C=> key and
  887. <SHIFT> key again.
  888.   The second function of the <C=> key is to  allow you access to a second
  889. set  of  eight  text colors.  By holding down the <C=> key and any of the
  890. number keys,  any text now typed will be in the alternate color available
  891. from  the  key  you depressed.  Chapter 5 lists the text colors available
  892. from each key.
  893.  
  894.  
  895. 2.2. Back to Normal
  896.  
  897.   Now  that you've had a chance to look over the keyboard,  let's explore
  898. some of the Commodore 64's many capabilities.
  899.   If  you  still have the color bars on the screen from adjusting your TV
  900. set, hold <SHIFT> and <CLR/HOME>.  The screen should clear and the cursor
  901. will  be  positioned  in  the  "home" spot (upper left-hand corner of the
  902. screen).
  903.   Now, simultaneously hold <C=> and the <7> key. This sets the text color
  904. back to light blue.  There is one more step needed to get everything back
  905. to normal. Hold <CTRL> and <0> (Zero not Oh!). This sets the display mode
  906. back  to  normal.  If  you  remember,  we turned REVERSE type on with the
  907. <CTRL><9> to create the color bars (the color bars were actually reversed
  908. spaces).  If  we were in the normal text mode during the color test,  the
  909. cursor would have moved, but just left blank spaces.
  910.  
  911.  
  912. TIP:
  913.  
  914.   Now  that  you've  done  things  the hard way, there is a simple way to
  915. reset the machine  to the normal display.  First press the <RUN/STOP> key
  916. and then press the <RESTORE> key.  <RUN/STOP> must always be held down in
  917. order to use the <RESTORE> key function.
  918.   This will clear the screen and return everything to normal. If there is
  919. a  program  in  the computer,  it will be left untouched.  This is a good
  920. sequence to remember, especially if you do a lot of programming.
  921.   If  you  wish  to  reset  the machine as if it were turned off and then
  922. switched on again, type,  SYS 64759  and press <RETURN>. Be careful using
  923. this  command!  It  will  wipe  out  any  program  or information that is
  924. currently in the computer.
  925.  
  926.  
  927. 2.3. Loading and Saving Programs
  928.  
  929.   One  of  the most important features of the Commodore 64 is the ability
  930. to save and load programs to and from cassette tape or disk.
  931.   This  capability allows you to save the programs you write for use at a
  932. later time, or purchase prewritten programs to use with the Commodore 64.
  933.   Make  sure  that  either  the  disk  drive or cassette unit is attached
  934. properly.
  935.  
  936.  
  937. LOADING PREPACKAGED PROGRAMS
  938.  
  939.   For  those  of  you  interested  in  using  only  prepackaged  programs
  940. available on cartridges, cassette, or disk here's all you have to do:
  941.  
  942. 1. CARTRIDGES: The Commodore 64 computer has a line of programs and games
  943. on cartridge.  The programs offer a wide variety of business and personal
  944. applications  and  the  games  are  just  like real arcade games  --  not
  945. imitations. To load these games, first turn on your TV set. Next turn OFF
  946. your  Commodore 64.  YOU MUST TURN OFF YOUR COMMODORE 64 BEFORE INSERTING
  947. OR  REMOVING  CARTRIDGES  OR  YOU  MAY  DAMAGE  THE CARTRIDGE AND/OR YOUR
  948. COMMODORE 64! Third insert the cartridge.  Now turn your Commodore 64 on.
  949. Finally  type  the  appropriate START key as is listed on the instruction
  950. sheet that comes with each game.
  951.  
  952. 2. CASSETTES:  Use  your  DATASSETTE  recorder  and  the  ordinary  audio
  953. cassettes  that  came as part of your prepackaged program.  Make sure the
  954. tape is completely rewound to the beginning of the first side.  Then just
  955. type  LOAD.  The  computer  will  answer with PRESS PLAY ON TAPE,  so you
  956. respond  by  pressing play on your datassette machine.  At this point the
  957. computer  screen  will go blank until the program is found.  The computer
  958. will say  FOUND (PROGRAM NAME)  on the screen.  Now you press down on the
  959. <C=> key.  This will actually load the program into the computer.  If you
  960. want to stop the loading simply press <RUN/STOP> key.
  961.  
  962. 3. DISK:  Using your disk drive,  carefully insert the preprogrammed disk
  963. so  that  the label on the disk is facing up and is closest to you.  Look
  964. for  a  little notch on the disk (it might be covered with a little piece
  965. of tape). If  you're inserting the disk properly the notch will be on the
  966. left side.  Once the disk is inside  close the protective gate by pushing
  967. down on the lever.  Now type  LOAD "PROGRAM NAME",8  and hit the <RETURN>
  968. key. The disk will make noise and your screen will say:
  969.  
  970.   SEARCHING FOR PROGRAM NAME
  971.   LOADING
  972.   READY.
  973.   _
  974.  
  975.   When  the  READY  comes  on  and  the  _ is on, just type RUN, and your
  976. prepackaged software is ready to use.
  977.  
  978.  
  979. LOADING PROGRAMS FROM TAPE
  980.  
  981.   Loading  a program back from tape or disk is just as simple.  For tape,
  982. rewind the tape back to the beginning and type:
  983.  
  984.   LOAD "PROGRAM NAME"
  985.  
  986.   If  you  don't remember the program name,  just type LOAD and the first
  987. program on the tape will be loaded into memory.
  988.   After you press <RETURN> the computer will respond with:
  989.  
  990.   PRESS PLAY ON TAPE
  991.  
  992.   After  you  depress  the  play  key, the screen will blank, turning the
  993. border color of the screen as the computer searches for the program.
  994.   When the program is found, the screen will display:
  995.  
  996.   FOUND PROGRAM NAME
  997.  
  998.   To  actually  load  the  program,  depress the <C=> key. To abandon the
  999. loading  procedure,  hit  <RUN/STOP>.  If  you hit the Commodore key, the
  1000. screen  will  again  turn  the  border color while the program is loaded.
  1001. After  the  loading procedure is completed, the screen will return to the
  1002. normal state and the READY prompt will reappear.
  1003.  
  1004.  
  1005. LOADING PROGRAMS FROM DISK
  1006.  
  1007.   Loading a program from disk follows the same format. Type:
  1008.  
  1009.   LOAD "PROGRAM NAME",8
  1010.  
  1011.   The  8  is  the  code for the disk, so you're just letting the computer
  1012. know that you want the program loaded from the disk.
  1013.   After  you  hit  <RETURN>  the disk will start whirring and the display
  1014. shows:
  1015.  
  1016.   SEARCHING FOR PROGRAM NAME
  1017.   LOADING
  1018.   READY.
  1019.   _
  1020.  
  1021. NOTE:
  1022.   When   you   load  a  new  program  into  the  computer's  memory,  any
  1023. instructions  that  were  in the computer previously will be erased. Make
  1024. sure  you  save  a  program  you're  working on before loading a new one.
  1025. Once a program has been loaded, you can RUN it, LIST, or make changes and
  1026. re-save the new version.
  1027.  
  1028.  
  1029. SAVING PROGRAMS ON TAPE
  1030.  
  1031.   After entering a program, if you wish to save it on tape, type:
  1032.  
  1033.   SAVE "PROGRAM NAME"
  1034.  
  1035.   "PROGRAM NAME" can be up to 16 characters long.  After you hit <RETURN>
  1036. the computer will respond with:
  1037.  
  1038.   PRESS PLAY AND RECORD ON TAPE
  1039.  
  1040.   Press both the record and play keys on the datassette.  The screen will
  1041. blank, turning the color of the border.
  1042.   After  the  program  is  saved on tape, the READY prompt will reappear,
  1043. indicating  that  you can start working on another program,  or just turn
  1044. off the computer for a while.
  1045.  
  1046.  
  1047. SAVING PROGRAMS ON DISK
  1048.  
  1049.   Saving a program on disk is even simpler. Type:
  1050.  
  1051.   SAVE "PROGRAM NAME",8
  1052.  
  1053.   The  8  is  the code for the disk,  so you're just letting the computer
  1054. know you want the program saved to disk.
  1055.   After you press  <RETURN>  the disk will start to turn and the computer
  1056. will respond with:
  1057.  
  1058.   SAVING PROGRAM NAME
  1059.   OK
  1060.   READY.
  1061.   _
  1062.  
  1063.  
  1064. 2.4. PRINT and Calculations
  1065.  
  1066.   Now  that  you've  gotten  through  a  couple  of  the  more  difficult
  1067. operations  you need  in order to keep the programs you like,  lets start
  1068. making some programs for you to save.
  1069.   Try typing the following exactly as shown:
  1070.  
  1071.   PRINT "COMMODORE 64"     <----- Type this line and hit <RETURN>
  1072.   COMMODORE 64            <------ Computer typed
  1073.  
  1074.   READY.
  1075.   _
  1076.  
  1077.   If  you  make  a  typing  mistake,  use the <INST/DEL> key to erase the
  1078. character  immediately  to the left of the cursor. You can delete as many
  1079. characters as necessary.
  1080.   Let's  see  what  went on in the example above.  First,  you instructed
  1081. (commanded) the computer to PRINT whatever was inside the quote marks. By
  1082. hitting  <RETURN>  you  told  the computer to do  what you instructed and
  1083. COMMODORE 64 was printed on the screen.
  1084.   When you use the PRINT statement in this form,  whatever is enclosed in
  1085. quotes is printed exactly as you typed it.
  1086.   If the computer responded with:
  1087.  
  1088.   ?SYNTAX ERROR
  1089.  
  1090. ask yourself if you made a mistake in typing,  or forgot the quote marks.
  1091. The  computer  is  precise  and  expects  instructions  to  be given in a
  1092. specific form.
  1093.   But don't get worried; just remember to enter things as we present them
  1094. in the examples and you'll get along great with the Commodore 64.
  1095.   Remember, you can't hurt the computer by typing on it, and the best way
  1096. to learn BASIC is to try different things and see what happens.
  1097.   PRINT  is  one  of  the  most useful and powerful commands in the BASIC
  1098. language.  With  it,  you  can  display  just  about  anything  you wish,
  1099. including graphics and results of computations.
  1100.   For example,  try the following.  Clear the screen  by holding down the
  1101. <SHIFT> key  and  <CLR/HOME> key and type (be sure to use the '1' key for
  1102. one, not a letter 'I'):
  1103.  
  1104.   PRINT 12 + 12            <----- Type this line and hit <RETURN>
  1105.   24                      <------ Computer printed the answer
  1106.  
  1107.   READY.
  1108.   _
  1109.  
  1110.   What you've discovered is  that the Commodore 64 is a calculator in its
  1111. basic form.  The result of "24" was calculated and printed automatically.
  1112. In  fact,  you can also perform  subtraction,  multiplication,  division,
  1113. exponentiation, and  advanced  math  functions such as calculating square
  1114. roots, etc. And you're not limited to a single calculation on a line, but
  1115. more on that later.
  1116.   Note  that in the above form,  PRINT behaved differently from the first
  1117. example.  In  this  case,  a value or result of a calculation is printed,
  1118. rather  than  the  exact message you entered because the quote marks were
  1119. omitted.
  1120.  
  1121.  
  1122. ADDITION
  1123.  
  1124.   The plus sign (+) signals addition: we instructed the computer to print
  1125. the result of 12 added to 12.  Other arithmetic operations take a similar
  1126. form to addition.  Remember to always hit <RETURN> after typing PRINT and
  1127. the calculation.
  1128.  
  1129.  
  1130. SUBTRACTION
  1131.  
  1132.   To subtract, use the conventional minus (-) sign. Type:
  1133.  
  1134.   PRINT 12 - 9             <----- Hit <RETURN>
  1135.   3
  1136.  
  1137.  
  1138. MULTIPLICATION
  1139.  
  1140.   If  you  wanted  to  multiply  12  times  12,  use  the asterisk (*) to
  1141. represent multiplication. You would type:
  1142.  
  1143.   PRINT 12 * 12            <----- Hit <RETURN>
  1144.   144
  1145.  
  1146.  
  1147. DIVISION
  1148.  
  1149.   Division uses the familiar "/". For example, to divide 144 by 12, type:
  1150.  
  1151.   PRINT 144 / 12           <----- Hit <RETURN>
  1152.   12
  1153.  
  1154.  
  1155. EXPONENTIATION
  1156.  
  1157.   In  a  like fashion,  you can easily raise a number to a power (this is
  1158. the same as multiplying a number by itself  a specified number of times).
  1159. The '^' (up arrow) signifies exponentiation.
  1160.  
  1161.   PRINT 12 ^ 5
  1162.   248832
  1163.  
  1164.   This is the same as typing:
  1165.  
  1166.   PRINT 12 * 12 * 12 * 12 * 12
  1167.   248832
  1168.  
  1169. TIP:
  1170.   BASIC  has  number  of  shortcut ways of doing things.  One such way is
  1171. abbreviating BASIC commands (or keywords).  A '?' can be used in place of
  1172. PRINT,  for example.  As we go on you'll be presented with many commands;
  1173. Appendix D shows the abbreviations for each and what will be displayed on
  1174. the screen when you type the abbreviated form.
  1175.  
  1176.   The  last example brings up another important point:  many calculations
  1177. may be performed on the same line, and they can be of mixed types.
  1178.   You could calculate this problem:
  1179.  
  1180.   ? 3 + 5 - 7 + 2          (The '?' replaces the word PRINT)
  1181.   3
  1182.  
  1183.   Up  to  this  point  we've just used small numbers and simple examples.
  1184. However, the Commodore 64 is capable of more complex calculations.
  1185.   You could,  for example,  add a number of large figures together.  Try
  1186. this, but don't use any commas, or you'll get an error:
  1187.  
  1188.   ? 123.45 + 345.78 + 7895.687
  1189.   8364.917
  1190.  
  1191.   That looks fine, but now try this:
  1192.  
  1193.   ? 12123123.45 + 345.78 + 7895.687
  1194.   12131364.9
  1195.  
  1196.   If you took the time to add this up by hand,  you would get a different
  1197. result.
  1198.   What's  going  on  here?  Even  though the computer has a lot of power,
  1199. there's  a limit to the numbers it can handle.  The Commodore 64 can work
  1200. with numbers containing 10 digits. However when a number is printed, only
  1201. nine digits are displayed.
  1202.   So in our example, the result was "rounded" to fit in the proper range.
  1203. The Commodore 64 rounds up when the next digit is five or more; it rounds
  1204. down when the next digit is four or less.
  1205.   Numbers  between  0.01  and  999,999,999  are  printed  using  standard
  1206. notation.  Numbers  outside  this  range  are  printed  using  scientific
  1207. notation.
  1208.   Scientific  notation  is  just  a process of expressing a very large or
  1209. small number as a power of 10.
  1210.   If you type:
  1211.  
  1212.   ? 123000000000000000
  1213.   1.23E+17
  1214.  
  1215.   This is the same as 1.23 * 10^17 and is used just to keep things tidy.
  1216.   There  is  a  limit  to  the  numbers  the computer can handle, even in
  1217. scientific notation. The limits are:
  1218.  
  1219.   Largest: +/- 1.70141183E+38
  1220.   Smallest (different from zero): +/- 2.93873588-39
  1221.  
  1222.  
  1223. 2.5. Precedence
  1224.  
  1225.   If  you  tried  to  perform  some mixed calculations different from the
  1226. examples  we  showed  earlier, you might not have gotten the results that
  1227. you expected.  The reason is that the computer performs calculations in a
  1228. certain order.
  1229.   In this calculation:
  1230.  
  1231.                                20 + 8 / 2
  1232.  
  1233. you  can't  tell  whether the answer should be 24 or 14 until you know in
  1234. which order to perform the calculations.  If you add 20 to 8 divided by 2
  1235. (or 4), then the result is 24. But,  if you add 20 plus 8 and then divide
  1236. by 2 the answer is 14. Try the example and see what result you get.
  1237.   The reason you got 24 is because the Commodore 64 performs calculations
  1238. left to right according to the following:
  1239.  
  1240. First :   -   minus sign indicating negative numbers
  1241. Second:   ^   exponentiation, left to right
  1242. Third :   */  multiplication and divisions, left to right
  1243. Fourth:   +-  addition and subtraction, left to right
  1244.  
  1245.   Follow  along  according  to  the order of precedence, and you will see
  1246. that  it  the above example the division was performed first and then the
  1247. addition to get a result of 24.
  1248.   Make  up  some problems of your own and see if you can follow along and
  1249. predict the results according to the rules set down above.
  1250.   There's  also  an  easy  way  to  alter the precedence process by using
  1251. parentheses to set off which operations you want performed first.
  1252.   For example, if you want to divide 35 by 5-plus-2 you type:
  1253.  
  1254.   ? 35 / 5 + 2
  1255.   9
  1256.  
  1257. you  will  get  35  divided by 5 with 2 added to the answer, which is not
  1258. what you intended at all. To get what you really wanted, try this:
  1259.  
  1260.   ? 35 / (5 + 2)
  1261.   5
  1262.  
  1263.   What  happens  now  is  that  the  computer evaluates what is contained
  1264. in  the  parentheses first.  If there are parentheses within parentheses,
  1265. the innermost parentheses are evaluated first.
  1266.   Where there are a number of parentheses on a line, such as:
  1267.  
  1268.   ? (12 + 9) * (6 + 1)
  1269.   147
  1270.  
  1271. the computer evaluates them left to right. Here 21 would be multiplied by
  1272. 7 for the result 147.
  1273.  
  1274.  
  1275. 2.6. Combining Things
  1276.  
  1277.   Even though we've spent a lot of time in areas that might not seem very
  1278. important, the details presented here will make more sense once you start
  1279. to program, and will prove invaluable.
  1280.   To  give  you an idea how things fit in place,  consider the following:
  1281. how could you combine the two types of PRINT statements we've examined so
  1282. far to print something more meaningful on the screen?
  1283.   We  know  that  by  enclosing  something within quote marks prints that
  1284. information  on  the screen exactly as it was entered,  and by using math
  1285. operators,  calculations  can  be  performed.  So why not combine the two
  1286. types of PRINT statements like this:
  1287.  
  1288.   ? "5 * 9 = "; 5 * 9      (Semicolon means no space)
  1289.   5 * 9 = 45
  1290.  
  1291.   Even though this might seem a bit redundant,  what we've done is simply
  1292. use  both  types  of  print  statements  together.  The first part prints
  1293. "5 * 9 ="  exactly as it was typed.  The second part does the actual work
  1294. and prints the result,  with the semicolon separating the message part of
  1295. the statement from the actual calculation.
  1296.   You  can separate the parts of a mixed PRINT statement with punctuation
  1297. for  various formats.  Try a comma in place of the semicolon and see what
  1298. happens.
  1299.   For the curious, the semicolon causes the next part of the statement to
  1300. be printed immediately after the previous part,  without any spaces.  The
  1301. comma   does  something  different.  Even  though  it  is  an  acceptable
  1302. separator, it spaces things out more. If you type:
  1303.  
  1304.   ? 2,3,4,5,6   <-------------------------------- Hit <RETURN>
  1305.   2            3            4             5
  1306.   6
  1307.  
  1308. the  numbers  will  be  printed across the screen and down on to the next
  1309. line.
  1310.   The  Commodore  64's  display  is  organized into 4 areas of 10 columns
  1311. each.  The  comma tabs each result into the next available area. Since we
  1312. asked  for  more  information  to  be printed than would fit on one line,
  1313. (we  tried  to  fit  five  10-column areas on one line) the last item was
  1314. moved down to the next line.
  1315.   The  basic  difference  between  the  comma and semicolon in formatting
  1316. PRINT  statements  can  be  used our advantage when creating more complex
  1317. displays: it allow us to create some sophisticated results very easily.
  1318.  
  1319.  
  1320.  
  1321. 3. BEGINNING BASIC PROGRAMMING
  1322.  
  1323.  
  1324. 3.1. The Next Step
  1325.  
  1326.   Up  to  now  we've  performed  some  simple  operations  by  entering a
  1327. single  line  of  instructions  into  the  computer.  Once  <RETURN>  was
  1328. depressed,  the  operation  that  we specified was performed immediately.
  1329. This is called the IMMEDIATE or CALCULATOR mode.
  1330.   But  to  accomplish  anything  significant, we must be able to have the
  1331. computer  operate  with  more  than  a single line statement. A number of
  1332. statements  combined  together  is called a PROGRAM and allows you to use
  1333. the full power of the Commodore 64.
  1334.   To  see  how  easy  it is to write your first Commodore 64 program, try
  1335. this:
  1336.  
  1337. Clear the screen by holding down the <SHIFT> key, and then depressing the
  1338. <CLR/HOME> key.
  1339. Type NEW and press <RETURN>. (This just clears out any numbers that might
  1340. have been left in the computer from your experimenting.)
  1341. Now type the following exactly as shown  (remember to hit <RETURN>  after
  1342. each line)
  1343.  
  1344.   10 ? "COMMODORE 64"
  1345.   20 GOTO 10
  1346.  
  1347.   Now, type RUN and hit <RETURN> -- watch what happens.  Your screen will
  1348. come alive with COMMODORE 64. After you've finished watching the display,
  1349. hit <RUN/STOP> to stop the program.
  1350.  
  1351.   COMMODORE 64
  1352.   COMMODORE 64
  1353.   COMMODORE 64
  1354.   COMMODORE 64
  1355.   COMMODORE 64
  1356.   COMMODORE 64
  1357.   COMMODORE 64
  1358.   COMMODORE 64
  1359.   COMMODORE 64
  1360.   COMMODORE 64
  1361.   COMMODORE 64
  1362.   COMMODORE 64
  1363.   BREAK IN 10
  1364.   READY
  1365.  
  1366.   A number of important concepts were introduced in  this  short  program
  1367. that are the basis for all programming.
  1368.   Notice  that here we preceded each statement with a number.  This  LINE
  1369. number tells the computer in what order  to  work  with  each  statement.
  1370. These  numbers  are also a reference point,  in case the program needs to
  1371. get  back  to  a  particular  line.  Line numbers can be any whole number
  1372. (integer) value between 0-63999.
  1373.  
  1374.   10 PRINT "COMMODORE 64"
  1375.   ^    ^
  1376.   |    |-- Statement
  1377.   |
  1378.   +------- Line number
  1379.  
  1380.   It is good programming practice to number lines in increments of 10  --
  1381. in case you need to insert some statements later on.
  1382.   Besides PRINT, our program also used another BASIC command, GOTO.  This
  1383. instructs the computer to go directly to a particular  line  and  perform
  1384. it, then continue from that point.
  1385.  
  1386.   +--> 10 PRINT "COMMODORE 64"
  1387.   |
  1388.   +--- 20 GOTO 10
  1389.  
  1390.   In our example,  the program prints the message in line 10, goes to the
  1391. next  line  (20),  which instructs it to go back to line 10 and print the
  1392. message over again.  Then the cycle repeats.  Since we  didn't  give  the
  1393. computer a way out of this loop, the program will cycle endlessly,  until
  1394. we physically stop it with the <RUN/STOP> key.
  1395.   Once  you've stopped the program,  type: LIST.  Your  program  will  be
  1396. displayed, intact,  because it's still in the computer's memory.  Notice,
  1397. too, that the computer converted the '?' into PRINT for you.  The program
  1398. can now be changed, saved, or run again.
  1399.   Another  important difference between typing something in the immediate
  1400. mode  and writing a program is that once you execute and clear the screen
  1401. of  an  immediate  statement,  it's lost.  However,  you can always get a
  1402. program back by just typing LIST.
  1403.   By  the  way,  when  it  comes  to  abbreviations don't forget that the
  1404. computer may run out of space on a line if you use too many.
  1405.  
  1406.  
  1407. 3.2. Editing Tips
  1408.  
  1409.   If you make a mistake on a line, you have a number of editing options.
  1410.  
  1411. 1. You can retype a line anytime,  and the  computer  will  automatically
  1412.    substitute the new line for the old one.
  1413. 2. An unwanted line can be erased by simply typing the  line  number  and
  1414.    <RETURN>.
  1415. 3. You can also easily edit an existing line,  using the cursor keys  and
  1416.    editing keys.
  1417.  
  1418.    Suppose you made a typing mistake in a line of the example. To correct
  1419. it without retyping the entire line, try this:
  1420.   Type LIST, then using the <SHIFT> and <CRSR UP/DOWN> keys together move
  1421. the  cursor  up  until  it  is  positioned  on  the line that needs to be
  1422. changed.
  1423.   Now,  use  the  cursor-right  key  to  move the cursor to the character
  1424. you  want  to  change,  typing the change over the old character. Now hit
  1425. <RETURN> and the corrected line will replace the old one.
  1426.   If you need more space on the line, position the cursor where the space
  1427. is needed and hit  <SHIFT>  and  <INST/DEL>  at the same time and a space
  1428. will  open  up.  Now  just  type  in  the  additional information and hit
  1429. <RETURN>.  Likewise,  you  can  delete unwanted characters by placing the
  1430. cursor to the right of the unwanted character and hitting the  <INST/DEL>
  1431. key.
  1432.   To verify that changes were entered, type LIST again, and the corrected
  1433. program  will  be  displayed!  And  lines  don't  have  to  be entered in
  1434. numerical order. The computer will automatically place them in the proper
  1435. sequence.
  1436.   Try editing our sample program on  Section 3.1  by changing line 10 and
  1437. adding a comma to the end of the line. Then RUN the program again.
  1438.  
  1439.   10 PRINT "COMMODORE",
  1440.  
  1441. Don't forget to move the cursor past line 20 before you RUN the program.
  1442.  
  1443.   COMMODORE   COMMODORE   COMMODORE   COMMODORE
  1444.   COMMODORE   COMMODORE   COMMODORE   COMMODORE
  1445.   COMMODORE   COMMODORE   COMMODORE   COMMODORE
  1446.   COMMODORE   COMMODORE   COMMODORE   COMMODORE
  1447.   COMMODORE   COMMODORE   COMMODORE   COMMODORE
  1448.   COMMODORE   COMMODORE   COMMODORE   COMMODORE
  1449.   COMMODORE   COMMODORE   COMMODORE   COMMODORE
  1450.   COMMODORE   COMMODORE   COMMODORE   COMMODORE
  1451.   COMMODORE   COMMODORE   COMMODORE   COMMODORE
  1452.   COMMODORE   COMMODORE   COMMODORE   COMMODORE
  1453.   COMMODORE   COMMODORE   COMMODORE   COMMODORE
  1454.   COMMODORE   COMMODORE   COMMODORE   COMMODORE
  1455.   COMMODORE   COMMODORE   COMMODORE   COMMODORE
  1456.   BREAK IN 10
  1457.   READY
  1458.  
  1459.  
  1460. 3.3. Variables
  1461.  
  1462.   Variables  are  some  of  the  most  used  features  of any programming
  1463. language,  because  variables  can represent much more information in the
  1464. computer.  Understanding how variables operate will make computing easier
  1465. and allow us to accomplish feats that would not be possible otherwise.
  1466.   Imagine a number of boxes within the computer that can hold a number or
  1467. a string of text characters.  Each of these boxes is to be labeled with a
  1468. name  that  we choose.  That name is called a variable and represents the
  1469. information in the respective box.
  1470.   For example, if we say:
  1471.  
  1472.   10 X% = 15
  1473.   20 X = 23.5
  1474.   30 X$ = "THE SUM OF X% + X ="
  1475.  
  1476.   The computer might represent the variables like this:
  1477.  
  1478.   X%  15
  1479.  
  1480.   X   23.5
  1481.  
  1482.   X$  THE SUM OF X% + X =
  1483.  
  1484.   A  variable  name  represents  the  box,  or memory location, where the
  1485. current  value  of  the variable is stored. As you can see, we can assign
  1486. either  an  integer  number, floating point number, or a text string to a
  1487. variable.
  1488.   The '%' symbol  following  a  variable name indicates the variable will
  1489. represent  an  integer  number.  The following are valid integer variable
  1490. names:
  1491.  
  1492.   A%
  1493.   X%
  1494.   A1%
  1495.   NM%
  1496.  
  1497.   The  '$'  following  the  variable  name  indicates  the  variable will
  1498. represent a text string. The following are examples of string variables:
  1499.  
  1500.   A$
  1501.   X$
  1502.   MI$
  1503.  
  1504.   Floating  point  variables  follow  the  same  format,  with  the  type
  1505. indicator:
  1506.  
  1507.   A1
  1508.   X
  1509.   Y
  1510.   MI
  1511.  
  1512.   In  assigning  a  name  to a variable there are a few things to keep in
  1513. mind.  First,  a  variable name can have one or two characters. The first
  1514. character  must  be  an  alphabetic  character  from  A to Z;  the second
  1515. character  can  be either alphabetic or numeric (in the range 0 to 9).  A
  1516. third character can be included to indicate the type of variable (integer
  1517. or text string), '%' or '$'.
  1518.   You can use variable names  having more than two alphabetic characters,
  1519. but  only the first two are recognized by the computer.  So PA and PARTNO
  1520. are the same and would refer to the same variable box.
  1521.   The  last  rule  for  variable names is simple:  they can't contain any
  1522. BASIC keywords  (reserved  words)  such as GOTO, RUN, etc.  Refer back to
  1523. Appendix D for a complete list of BASIC reserved words.
  1524.   To see how variables can be put to work,  type in  the complete program
  1525. that we introduced earlier and  RUN it.  Remember to hit  <RETURN>  after
  1526. each line in the program.
  1527.  
  1528.   NEW
  1529.  
  1530.   10 X% = 15
  1531.   20 X = 23.5
  1532.   30 X$ = "THE SUM OF X% + X ="
  1533.   40 PRINT "X% = "; X%, "X = "; X
  1534.   50 PRINT X$; X% + X
  1535.  
  1536.   If  you  did  everything  as shown, you should get the following result
  1537. printed on the screen.
  1538.  
  1539.   RUN
  1540.   X% = 15    X = 23.5
  1541.   THE SUM OF X% + X = 38.5
  1542.   READY
  1543.  
  1544.   We've put together all the tricks learned so far  to format the display
  1545. as you see it and print the sum of the two variables.
  1546.   In lines  10 and 20  we assigned an integer value to X%  and assigned a
  1547. floating  point  value  to  X.  This puts the number  associated with the
  1548. variable in its box. In line 30, we assigned a text string to X$. Line 40
  1549. combines  the  two  types  of PRINT statements to print a message and the
  1550. actual value of  X% and X.  Line 50 prints the text string assigned to X$
  1551. and the sum of X% and X.
  1552.   Note  that  even  though  X  is used as part of each variable name, the
  1553. identifiers '%' and '$' make  X%,  X,  and  X$ unique,  thus representing
  1554. three distinct variables.
  1555.   But  variables are much more powerful.  If you change their value,  the
  1556. new value replaces the original value in the same box. This allows you to
  1557. write a statement like:
  1558.  
  1559.   X = X + 1
  1560.  
  1561.   This would never be accepted in normal algebra,  but is one of the most
  1562. used concepts in programming.  It means: take the current value of X, add
  1563. one to it and place the new sum into the box representing X.
  1564.  
  1565.  
  1566. 3.4. IF ... THEN
  1567.  
  1568.   Armed with the ability to easily update the value of variables,  we can
  1569. now try a program such as:
  1570.  
  1571.   NEW
  1572.  
  1573.   10 CT = 0
  1574.   20 ? "COMMODORE 64"
  1575.   30 CT = CT + 1
  1576.   40 IF CT < 5 THEN 20
  1577.   50 END
  1578.  
  1579.   RUN
  1580.   COMMODORE 64
  1581.   COMMODORE 64
  1582.   COMMODORE 64
  1583.   COMMODORE 64
  1584.   COMMODORE 64
  1585.  
  1586.   What we've done is introduce two new BASIC commands,  and provided some
  1587. control  over our runaway little print program introduced at the start of
  1588. this chapter.
  1589.   IF ... THEN adds some logic to the program.  If  says  IF  a  condition
  1590. holds true THEN do something. IF the condition no longer holds true, THEN
  1591. do the next line in the program.
  1592.   A number of conditions can be set up in using an IF ... THEN statement:
  1593.  
  1594.   SYMBOL      MEANING
  1595.     <         Less Than
  1596.     >         Greater Than
  1597.     =         Equal To
  1598.     <>        Not Equal To
  1599.     >=        Greater Than or Equal To
  1600.     <=        Less Than or Equal To
  1601.  
  1602.   The  use  of  any  one  of these conditions is simple, yet surprisingly
  1603. powerful.
  1604.  
  1605.        10 CT = 0
  1606.   +--> 20 ? "COMMODORE 64"
  1607.   |    30 CT = CT + 1
  1608.   +-<- 40 IF CT < 5 THEN 20
  1609.        |
  1610.        !
  1611.        50 END
  1612.  
  1613.   In the sample program,  we've set up a "loop"  that has some constrains
  1614. placed  on  it  by  saying:  IF a value is less than some number  THEN do
  1615. something.
  1616.   Line 10 sets CT (CounT) equal to 0. Line 20 prints our message. Line 30
  1617. adds one  to the variable CT.  This line counts  how many times we do the
  1618. loop. Each time the loop is executed, CT goes up by one.
  1619.   Line  40  is  our  control  line.  If  CT is less than 5, meaning we've
  1620. executed the loop less than 5 times, the program goes back to line 20 and
  1621. prints again.  When CT becomes equal to 5  -- indicating 5 COMMODORE 64's
  1622. were  printed  --  the program goes to line 50,  which signals to END the
  1623. program.
  1624.   Try  program  and see what we mean. By changing the CT limit in line 40
  1625. you can have any number of lines printed.
  1626.   IF ... THEN  has  a  multitude of other uses, which we'll see in future
  1627. examples.
  1628.  
  1629.  
  1630. 3.5. FOR ... NEXT Loops
  1631.  
  1632.   There is a simpler,  and preferred way to accomplish what we did in the
  1633. previous example by using a FOR ... NEXT loop. Consider the following:
  1634.  
  1635.   NEW
  1636.  
  1637.   10 FOR CT = 1 TO 5
  1638.   20 ? "COMMODORE 64"
  1639.   30 NEXT CT
  1640.  
  1641.   RUN
  1642.   COMMODORE 64
  1643.   COMMODORE 64
  1644.   COMMODORE 64
  1645.   COMMODORE 64
  1646.   COMMODORE 64
  1647.  
  1648.   As you can see, the program has become much smaller and more direct.
  1649.   CT starts at 1 in line 10. Then, line 20 does some printing. In line 30
  1650. CT is incremented by 1. The NEXT statement in line 30 automatically sends
  1651. the  program  back  to  line 10  where the FOR part  of the  FOR ... NEXT
  1652. statement  is  located.  This process will continue  until CT reaches the
  1653. limit you entered.
  1654.   The variable  used in a FOR ... NEXT loop can be incremented by smaller
  1655. amounts than 1, if needed.
  1656.   Try this:
  1657.  
  1658.   NEW
  1659.  
  1660.   10 FOR NB = 1 TO 10 STEP .5
  1661.   20 PRINT NB,
  1662.   30 NEXT NB
  1663.  
  1664.   RUN
  1665.   1          1.5           2             2.5
  1666.   3          3.5           4             4.5
  1667.   5          5.5           6             6.5
  1668.   7          7.5           8             8.5
  1669.   9          9.5           10
  1670.  
  1671.   If you enter and run this program, you'll see the numbers from 1 to 10,
  1672. by .5, printed across the display.
  1673.   All we're doing here  is printing the values that NB assumes as it goes
  1674. through the loop.
  1675.   You can even specify  whether the variable is increasing or decreasing.
  1676. Substitute the following for line 10:
  1677.  
  1678.   10 FOR NB = 10 TO 1 STEP -.5
  1679.  
  1680. and  watch  the  opposite  occur,  as  NB goes from 10 to 1 in descending
  1681. order.
  1682.  
  1683.  
  1684.  
  1685. 4. ADVANCED BASIC
  1686.  
  1687.  
  1688. 4.1. Introduction
  1689.  
  1690.   The  next  few  chapters  have  been written for people who have become
  1691. relatively  familiar with the BASIC programming language and the concepts
  1692. necessary to write more advanced programs.
  1693.   For  those of you who are just staring to learn how to program, you may
  1694. find   some  of  the  information  a  bit  too  technical  to  understand
  1695. completely. But take heart ... because for these two fun chapters, SPRITE
  1696. GRAPHICS and  CREATING SOUND,  we've set up some simple examples that are
  1697. written  for the new user.  The examples will give you a good idea of how
  1698. to  use  the  sophisticated  sound and graphics capabilities available on
  1699. your COMMODORE 64.
  1700.   If  you  decide  that  you want to learn more about writing programs in
  1701. BASIC, we've put a bibliography (Appendix N) in the back of this manual.
  1702.   If you are already familiar with BASIC programming, these chapters will
  1703. help  you  get  started with advanced BASIC programming techniques.  More
  1704. detailed  information  can  be  found  in  the  COMMODORE 64 PROGRAMMER'S
  1705. REFERENCE MANUAL, available through your local Commodore dealer.
  1706.  
  1707.  
  1708. 4.2. Simple Animation
  1709.  
  1710.   Let's  exercise  some  of  the  Commodore 64's  graphic capabilities by
  1711. putting  together  what  we've  seen  so  far,  together  with  a few new
  1712. concepts. If you're ambitious, type in the following program and see what
  1713. happens.  You  will  notice  that within the print statements we can also
  1714. include cursor controls and screen commands.  When you see something like
  1715. {CRSR LEFT} in a program listing,  hold the <SHIFT> key and hit the <CRSR
  1716. LEFT/RIGHT>  key.  The  screen  will show the graphic representation of a
  1717. cursor  left  (two  vertical reversed bars).  In  the same way,  pressing
  1718. <SHIFT> and <CLR/HOME> shows as a reversed heart.
  1719.  
  1720.   NEW
  1721.  
  1722.   10  REM BOUNCING BALL
  1723.   20  PRINT "{CLR/HOME}"
  1724.   25  FOR X=1 to 10 : PRINT "{CRSR DOWN}" : NEXT
  1725.   30  FOR BL=1 to 40
  1726.   40  PRINT" O{CRSR LEFT}"; : REM (O is a SHIFT-Q)
  1727.   50  FOR TM=1 TO 5
  1728.   60  NEXT TM
  1729.   70  NEXT BL
  1730.   75  REM MOVE BALL RIGHT TO LEFT
  1731.   80  FOR BL=40 TO 1 STEP -1
  1732.   90  PRINT" {CRSR LEFT}{CRSR LEFT}O{CRSR LEFT}";
  1733.   100 FOR TM=1 TO 5
  1734.   110 NEXT TM
  1735.   120 NEXT BL
  1736.   130 GOTO 20
  1737.  
  1738. NOTES:  The  ':' in lines 25 and 40 indicates new command.  The spaces in
  1739. lines 40 and 90 are intentional.
  1740.  
  1741. TIP: All  words in this text will be completed on one line.  However,  as
  1742. long  as  you  don't  hit <RETURN> your 64 will automatically move to the
  1743. next line even in the middle of a word.
  1744.  
  1745.   The program will display a bouncing ball moving from left to right, and
  1746. back again, across the screen.
  1747.   If  we  look  at  the  program  closely,  you can see how this feat was
  1748. accomplished.
  1749.  
  1750.        10  REM BOUNCING BALL
  1751. +----> 20  PRINT "{CLR/HOME}"
  1752. | +--> 25  FOR X=1 to 10 : PRINT "{CRSR DOWN}" : NEXT
  1753. | |    30  FOR BL=1 to 40
  1754. | |    40  PRINT" O{CRSR LEFT}"; : REM (O is a SHIFT-Q)
  1755. | | +> 50  FOR TM=1 TO 5
  1756. | | +- 60  NEXT TM
  1757. | +--- 70  NEXT BL
  1758. |      75  REM MOVE BALL RIGHT TO LEFT
  1759. | +--> 80  FOR BL=40 TO 1 STEP -1
  1760. | |    90  PRINT" {CRSR LEFT}{CRSR LEFT}O{CRSR LEFT}";
  1761. | | +> 100 FOR TM=1 TO 5
  1762. | | +- 110 NEXT TM
  1763. | +--- 120 NEXT BL
  1764. +----- 130 GOTO 20
  1765.  
  1766.   Line  10  is a REMark that just tells what the program does;  it has no
  1767. effect  on  the  program  itself.  Line  20  clears  the  screen  of  any
  1768. information.
  1769.   Line 25 PRINTs 10 cursor-down commands. This just positions the ball in
  1770. the middle of the screen.  If line 25 was eliminated  the ball would move
  1771. across the top line of the screen.
  1772.   Line 30 sets up a loop for moving the ball the 40 columns from the left
  1773. to right.
  1774.   Line 40  does  a  lot  of  work.  It  first prints a space to erase the
  1775. previous ball positions, then it prints the ball, and finally it performs
  1776. a cursor-left  to get everything ready to erase the current ball position
  1777. again.
  1778.   The  loop  set  up  in  lines  50  and  60 slows the ball down a bit by
  1779. delaying the program. Without it, the ball would move too fast to see.
  1780.   Line 70  completes the loop that prints balls on the screen,  set up in
  1781. line 30.  Each time the loop is executed, the ball moves another space to
  1782. the  right.  As  you notice from the illustration,  we have set up a loop
  1783. within a loop.
  1784.   This is perfectly acceptable.  The only time you get in trouble is when
  1785. the  loops  cross  over  each other.  It's helpful in writing programs to
  1786. check  yourself  as  illustrated here to make sure the logic of a loop is
  1787. correct.
  1788.   To see what would happen if you cross a loop, reverse the statements in
  1789. lines 60 and 70. You will get an error because the computer gets confused
  1790. and cannot figure out what's going on.
  1791.   Lines  80  through  120 just reverse the steps in the first part of the
  1792. program,  and  move  the  ball  from  right to left.  Line 90 is slightly
  1793. different  from  line  40  because  the  ball  is  moving in the opposite
  1794. direction (we have to erase the ball to the right and move to the left).
  1795.   And when that's all done  the program goes back to line 20 to start the
  1796. whole  process  over  again.  Pretty neat!  To stop the program hold down
  1797. <RESTORE> and hit <RUN/STOP>.
  1798.   For a variation on the program, edit line 40 to read:
  1799.  
  1800.   40 PRINT"O";  To make the O, hold SHIFT key down and hit the letter "Q"
  1801.  
  1802.   Run  the  program  and  see  what happens now.  Because we left out the
  1803. cursor control,  each ball remains on the screen until erased by the ball
  1804. moving right to left in the second part of the program.
  1805.  
  1806.  
  1807. 4.3. INPUT
  1808.  
  1809.   Up  to now,  everything within a program has been set before it is run.
  1810. Once the program was started,  nothing could be changed.  INPUT allows us
  1811. to  pass  new information to a program as it is running and have that new
  1812. information acted upon.
  1813.   To get an idea of how INPUT works,  type  NEW  <RETURN>  and enter this
  1814. short program:
  1815.  
  1816.   10 INPUT A$
  1817.   20 PRINT "YOU TYPED: ";A$
  1818.   30 PRINT
  1819.   40 GOTO 10
  1820.   RUN
  1821.   ? COMMODORE 64  <--------------- You typed
  1822.   YOU TYPED: COMMODORE 64   <----- Computer responded
  1823.  
  1824.   What  happens  when  you  run this simple program. A question mark will
  1825. appear,  indicating  that  the  computer  is  waiting  for  you  to  type
  1826. something. Enter any character, or group of characters, from the keyboard
  1827. and  hit  <RETURN>.  The  computer  will  then  respond with "YOU TYPED:"
  1828. followed by the information you entered.
  1829.   This  may  seem  very  elementary,  but  imagine  what you can have the
  1830. computer do with any information you enter.
  1831.   You  can  INPUT  either numeric or string variables,  and even have the
  1832. INPUT statement prompt the user with a message. The format of INPUT is:
  1833.  
  1834.   INPUT "PROMPT MESSAGE";VARIABLE
  1835.          ^
  1836.          +---- Prompt must be 38 characters or less
  1837.  
  1838. Or, just:
  1839.  
  1840.   INPUT VARIABLE
  1841.  
  1842. NOTE:  To  get out of this program hold down the <RUN/STOP> and <RESTORE>
  1843. keys.
  1844.  
  1845.   The  following  program  is not only useful,  but demonstrates a lot of
  1846. what has been presented so far, including the new input statement.
  1847.  
  1848.   NEW
  1849.  
  1850.     1 REM TEMPERATURE CONVERSION PROGRAM
  1851.     5 PRINT "{CLR/HOME}"
  1852.    10 PRINT "CONVERT FROM FAHRENHEIT OR CELSIUS (F/C): ": INPUT A$
  1853.    20 IF A$ = "" THEN 10  <----------------------- No space within quotes
  1854.    30 IF A$ = "F" THEN 100
  1855.    40 IF A$ <> "C" THEN 10
  1856.    50 INPUT "ENTER DEGREES CELSIUS: ";C
  1857.    60 F = (C*9)/5+32
  1858.    70 PRINT C;" DEG. CELSIUS ="; F ;"DEG. FAHRENHEIT"
  1859.    80 PRINT
  1860.    90 GOTO 10
  1861.   100 INPUT "ENTER DEGREES FAHRENHEIT: ";F  <- Don't forget to hit RETURN
  1862.   110 C = (F-32)*/5/9
  1863.   120 PRINT F;" DEG. FAHRENHEIT ="; C ;"DEG. CELSIUS"
  1864.   130 PRINT
  1865.   140 GOTO 10
  1866.  
  1867.   If you entered and run this program, you'll see INPUT in action.
  1868.   Line 10  uses  the input statement to not only gather information,  but
  1869. also print our prompt. Also notice that we can ask for either a number or
  1870. string (by using a numeric or string variable).
  1871.   Lines 20, 30, and 40 do some checks on what is typed in. In line 20, if
  1872. nothing is entered (just <RETURN> is hit),  then the program goes back to
  1873. line 10 and requests the input again. In line 30, if F is typed, you know
  1874. the user wants to convert a temperature in degrees Fahrenheit to Celsius,
  1875. so the program branches to the part that does that conversion.
  1876.   Line  40 does one more check.  We know there are only two valid choices
  1877. the  user  can enter.  To get to line 40,   the user must have typed some
  1878. character other than F.  Now, a check is made to see if that character is
  1879. a C; if not, the program requests input again.
  1880.   This  may  seem  like  a  lot  of  detail,  but  it is good programming
  1881. practice. A user not familiar with the program can become very frustrated
  1882. if  it  does  something  strange  because  a  mistake  was  made entering
  1883. information.
  1884.   Once we determine what type of conversion to perform,  the program does
  1885. the  calculation and prints out the temperature entered and the converted
  1886. temperature.
  1887.   The  calculation  is just straight math,  using the established formula
  1888. for temperature conversion.  After the calculation is finished and answer
  1889. printed, the program loops back and starts over.
  1890.   After running, the screen might look like this:
  1891.  
  1892.   CONVERT FROM FAHRENHEIT OR CELSIUS (F/C): ? F
  1893.   ENTER DEGREES FAHRENHEIT: 32
  1894.   32 DEG. FAHRENHEIT = 0 DEG. CELSIUS
  1895.  
  1896.   CONVERT FROM FAHRENHEIT OR CELSIUS (F/C): ?
  1897.  
  1898.   After running the program,  make sure to save it on disk or tape.  This
  1899. program,  as well as others presented throughout the manual, can form the
  1900. base of your program library.
  1901.  
  1902.  
  1903. 4.4. GET
  1904.  
  1905.   GET  allows  you  to  input  one  character at a time from the keyboard
  1906. without  hitting  <RETURN>.  This  really  speeds  entering  data in many
  1907. applications.  Whatever  key  is hit is assigned variable to the variable
  1908. you specify with GET.
  1909.   The following routine illustrates how GET works:
  1910.  
  1911.   NEW
  1912.  
  1913.    1 PRINT "{CLR/HOME}"
  1914.   10 GET A$: IF A$ = "" THEN 10
  1915.   20 PRINT A$;        ^
  1916.   30 GOTO 10          |-------------- No SPACE here
  1917.  
  1918.   If you RUN the program,  the screen will clear  and each time you hit a
  1919. key,  line  20  will  print  it  on  the  display,  and  then GET another
  1920. character. It is important to note that the character entered will not be
  1921. displayed  unless you specifically PRINT it to the screen,  as we've done
  1922. here.
  1923.   The  second  statement  on  line 10 is also important.  GET continually
  1924. works,  even  if  no  key  is  pressed  (unlike  INPUT  that  waits for a
  1925. response),  so  the  second  part  of  this  line  continually checks the
  1926. keyboard until a key is hit.
  1927.   See what happens if the second part of line 10 is eliminated.
  1928.   To stop this program you can hit the <RUN/STOP> and <RESTORE> keys.
  1929.   The  first  part  of the temperature conversion program could easily be
  1930. rewritten to use GET. LOAD the temperature conversion program, and modify
  1931. lines 10,20 and 40 as shown:
  1932.  
  1933.   10 PRINT "CONVERT FROM FAHRENHEIT OR CELSIUS (F/C) ?"
  1934.   20 GET A$: IF A$ = "" THEN 20  <---------------- No space within quotes
  1935.   30 IF A$ <> "C" THEN 20
  1936.  
  1937.   This  modification  will  make the program operate smoother, as nothing
  1938. will  happen  unless  the  user  types in one of the desired responses to
  1939. select the type of conversion.
  1940.   Once  this  change  is made,  make sure you save the new version of the
  1941. program.
  1942.  
  1943.  
  1944. 4.5. Random Numbers and Other Functions
  1945.  
  1946.   The  Commodore 64  contains  a  number  of  functions  that are used to
  1947. perform  special  operations.  Functions  could be thought of as built-in
  1948. programs  included  in  BASIC.  But  rather  than  typing  in a number of
  1949. statements  each time you need to perform a specialized calculation,  you
  1950. just  type the command for the desired function and the computer does the
  1951. rest.
  1952.   Many  times  when designing a game or educational program,  you need to
  1953. generate a random number, to simulate the throw of dice, for example. You
  1954. could certainly write a program that would generate these numbers, but an
  1955. easier way to call upon the RaNDom number function.
  1956.   To see what RND actually does, try this short program:
  1957.  
  1958.   NEW
  1959.  
  1960.   10 FOR X = 1 TO 10
  1961.   20 PRINT RND(1),    <------------ If you leave out the comma, your list
  1962.   30 NEXT                           of numbers will appear as 1 column
  1963.  
  1964.   After running the program, you will see a display like this:
  1965.  
  1966.    .789280697          .664673958
  1967.    .256373663          .0123442287
  1968.    .682952381          3.90587279E-04
  1969.    .402343724          .879300926
  1970.    .158209063          .245596701
  1971.  
  1972.   Your numbers don't match? Well, if they did we would all be in trouble,
  1973. as they should be completely random!
  1974.   Try running the program a few more times to verify that the results are
  1975. always  different.  Even  if  the  numbers don't follow any pattern,  you
  1976. should  start  to  notice that some things remain the same every time the
  1977. program is run.
  1978.   First,  the results are always between 0 and 1, but never equal to 0 or
  1979. 1. This will certainly never do if we want to simulate the random toss of
  1980. dice, since we're looking for numbers between 1 and 6.
  1981.   The  other  important  feature  to look for is that we are dealing with
  1982. real  numbers  (with decimal places).  This could also be a problem since
  1983. whole (integer) numbers are often needed.
  1984.   There  are  a  number  of  simple  ways to produce numbers from the RND
  1985. function in the range desired.
  1986.   Replace line 20 with following and run the program again:
  1987.  
  1988.   20 PRINT 6*RND(1),
  1989.  
  1990.   RUN
  1991.  
  1992.    3.60563664          4.53660853
  1993.    5.47238963          8.40850227
  1994.    3.19265054          4.39547668
  1995.    3.16331095          5.50620749
  1996.    9.32527884          4.17090293
  1997.  
  1998.   That  cured  the  problem  of not having results larger than 1,  but we
  1999. still  have  the  decimal part of the result to deal with.  Now,  another
  2000. function can be called upon.
  2001.   The INTeger function converts real numbers into integer values.
  2002.   Once  more,  replace  line 20 with the following and run the program to
  2003. see the effect of the change:
  2004.  
  2005.   20 PRINT INT(6*RND(1)),
  2006.  
  2007.   RUN
  2008.  
  2009.    2         3         1         0
  2010.    2         4         5         5
  2011.    0         1
  2012.  
  2013.   That  took  care  of  a lot,  getting us closer to our original goal of
  2014. generating random numbers between 1 and 6. If you examine closely what we
  2015. generated this last time, you'll find that the results range from 0 to 5,
  2016. only.
  2017.   As a last step, add a one to the statement, as follows:
  2018.  
  2019.   20 PRINT INT(6*RND(1))+1,
  2020.  
  2021.   Now, we have achieved the desired results.
  2022.   In general,  you can place a number, variable,  or any BASIC expression
  2023. within  the  parentheses  of  the  INT  function.  Depending on the range
  2024. desired,  you  just  multiply  the  upper limit by the RND function.  For
  2025. example, to generate random numbers between 1 and 25, you could type:
  2026.  
  2027.   20 PRINT INT(25*RND(1))+1,
  2028.  
  2029.   The general formula for generating a set of random numbers in a certain
  2030. range is:
  2031.  
  2032.   NUMBER=INT(LOWER+(UPPER-LOWER+1)*RND(1))
  2033.  
  2034.  
  2035. 4.6. Guessing Game
  2036.  
  2037.   Since we've gone to some lengths to understand random numbers,  why not
  2038. put  this  information to use?  The following game not only illustrates a
  2039. good  use  of  random  numbers,   but  also  introduces  some  additional
  2040. programming theory.
  2041.   In running this program, a random number, NM, will be generated.
  2042.  
  2043.   NEW
  2044.  
  2045.     1 REM NUMBER GUESSING GAME
  2046.     2 PRINT "{CLR/HOME}"
  2047.     5 INPUT "ENTER UPPER LIMIT FOR GUESS ";LI
  2048.    10 NM = INT(LI*RND(1))+1
  2049.    15 CN = 0
  2050.    20 PRINT "I'VE GOT THE NUMBER." : PRINT
  2051.    30 INPUT "WHAT'S YOUR GUESS "; GU
  2052.    35 CN = CN + 1
  2053.    40 IF GU > NM THEN PRINT "MY NUMBER IS LOWER." : PRINT : GOTO 30
  2054.    50 IF GU < NM THEN PRINT "MY NUMBER IS HIGHER.": PRINT : GOTO 30
  2055.    60 PRINT "GREAT! YOU GOT MY NUMBER"
  2056.    65 PRINT "IN ONLY"; CN ;"GUESSES." : PRINT
  2057.    70 PRINT "DO YOU WANT TO TRY ANOTHER (Y/N) ?";
  2058.    80 GET AN$ : IF AN$ = "" THEN 80
  2059.    90 IF AN$ = "Y" THEN 2
  2060.   100 IF AN$ <> "N" THEN 70
  2061.   110 END
  2062.  
  2063.   You  can  specify  how  large  the  number  will be at the start of the
  2064. program. Then, it's up to you to guess what the number is.
  2065.   A sample run follows along with an explanation.
  2066.  
  2067.   ENTER UPPER LIMIT FOR GUESS ? 25
  2068.   I'VE GOT THE NUMBER.
  2069.  
  2070.   WHAT'S YOUR NUMBER GUESS ? 15
  2071.   MY NUMBER IS HIGHER.
  2072.  
  2073.   WHAT'S YOUR NUMBER GUESS ? 20
  2074.   MY NUMBER IS LOWER.
  2075.  
  2076.   WHAT'S YOUR NUMBER GUESS ? 19
  2077.   GREAT! YOU GOT MY NUMBER
  2078.   IN ONLY 3 GUESSES.
  2079.  
  2080.   DO YOU WANT TO TRY ANOTHER (Y/N) ?
  2081.  
  2082.   IF/THEN   statements  compare  your  guess  to  the  number  generated.
  2083. Depending  on  your  guess,  the program tells you whether your guess was
  2084. higher or lower than the random number generated.
  2085.   From the formula given for determining random number range,  see if you
  2086. can  add  a  few lines to the program that allow the user to also specify
  2087. the lower range of numbers generated.
  2088.   Each time you make a guess, CN is incremented by 1 to keep track of the
  2089. number  of  guesses.  In  using  the  program,  see  if  you can use good
  2090. reasoning to guess a number in the least number of tries.
  2091.   When  you get the right answer,  the program prints out the "GREAT! YOU
  2092. GOT MY NUMBER" message,  along with the number of tries it took.  You can
  2093. then start the process over again.  Remember, the program generates a new
  2094. random number each time.
  2095.  
  2096. PROGRAMMING TIPS:
  2097.  
  2098.   In line 40 and 50, a colon is used to separate multiple statements on a
  2099. single  line.  This  not  only  saves  typing,  but in long programs will
  2100. conserve memory space.
  2101.   Also  notice  in  the  IF/THEN  statements  on  the same two lines,  we
  2102. instructed  the  computer  to  PRINT  something,  rather than immediately
  2103. branching to some other point in the program.
  2104.   The  last  point  illustrates  the  reason behind using line numbers in
  2105. increments of  10.  After the program was written,  we decided to add the
  2106. count  part.  By  just  adding those new lines at the end of the program,
  2107. numbered  to  fall  between  the  proper existing lines,  the program was
  2108. easily modified.
  2109.  
  2110.  
  2111. 4.7. Your Roll
  2112.  
  2113.   The following program simulates the throw of two dice. You can enjoy it
  2114. as it stands, or use it as part of a larger game.
  2115.  
  2116.    5 PRINT "CARE TO TRY YOUR LUCK?"
  2117.   10 PRINT "RED DICE   =";INT(6*RND(1))+1
  2118.   20 PRINT "WHITE DICE =";INT(6*RND(1))+1
  2119.   30 PRINT "HIT SPACE BAR FOR ANOTHER ROLL" : PRINT
  2120.   40 GET A$ : IF A$ = "" THEN 40
  2121.   50 IF A$ = CHR$(32) THEN 10
  2122.  
  2123.   From what you've learned about random numbers and BASIC, see if you can
  2124. follow what is going on.
  2125.  
  2126.  
  2127. 4.8. Random Graphics
  2128.  
  2129.   As a final note on random numbers,  and as an introduction to designing
  2130. graphics, take a moment to enter and run this neat little program:
  2131.  
  2132.   10 REM MAZE
  2133.   20 PRINT "{CLR/HOME}"
  2134.   30 PRINT CHR$(205.5+RND(1));
  2135.   40 GOTO 20
  2136.  
  2137.   As  you  may have expected,  line 20 is the key here. Another function,
  2138. CHR$ (Character String),  gives you a character, based on a standard code
  2139. number  from  0  to  255.  Every  character the Commodore 64 can print is
  2140. encoded this way (see Appendix F).
  2141.   To quickly find out the code for any character, just type:
  2142.  
  2143.   PRINT ASC("X")
  2144.  
  2145. where  X  is  the  character  you're checking  (this can be any printable
  2146. character,  including  graphics).  The  response  is  the  code  for  the
  2147. character  you  typed.  As  you  probably  figured out,  "ASC" is another
  2148. function,  which  returns the standard "ASCII" code for the character you
  2149. typed.
  2150.   You can now print that character by typing:
  2151.  
  2152.   PRINT CHR$(X)
  2153.  
  2154.   If you try typing:
  2155.  
  2156.   PRINT CHR$(205); CHR$(206)
  2157.  
  2158. you  will  see the two right side graphic characters on the M and N keys.
  2159. These are two characters that the program is using for the maze.
  2160.   By  using  the  formula  205.5 + RND(1) the computer will pick a random
  2161. number  between  205.5  and  206.5.  There is a fifty-fifty chance of the
  2162. number being above or below 206.  CHR$ ignores any fractional values,  so
  2163. half  the  time  the character with code 205 is printed and the remaining
  2164. time code 206 is displayed.
  2165.   If  you'd  like to experiment with this program,  try changing 205.5 by
  2166. adding  or  subtracting  a couple  tenths from it.  This will give either
  2167. character a greater chance of being selected.
  2168.  
  2169.  
  2170.  
  2171. 5. ADVANCED COLOR AND GRAPHIC COMMANDS
  2172.  
  2173.  
  2174. 5.1. Color and Graphics
  2175.  
  2176.   Up   to   now  we've  explored  some  of  the  sophisticated  computing
  2177. capabilities  of  the  Commodore 64.  But  one  of  its  most fascinating
  2178. features is an outstanding ability to produce color and graphics.
  2179.   You've  seen  a  quick example  of  graphics in the "bouncing ball" and
  2180. "maze"  programs.  But  these  only  touched  on the power you command. A
  2181. number  of  new  concepts  will  be introduced in this section to explain
  2182. graphic  and color programming and show how you can create your own games
  2183. and advanced animation.
  2184.   Because  we've  concentrated  on  the  computing  capabilities  of  the
  2185. machine,  all  the  displays  we've  generated so far were a single color
  2186. (light blue text on a dark blue background, with a light blue border).
  2187.   In this chapter we'll see how to add color to programs  and control all
  2188. those strange graphic symbols on the keyboard.
  2189.  
  2190.  
  2191. 5.2. PRINTing Colors
  2192.  
  2193.   As  you discovered  if you tried the color alignment test in Chapter 1,
  2194. you  can  change  text colors by simply holding the <CTRL> key and one of
  2195. the color keys.  This works fine in the immediate mode,  but what happens
  2196. if you want to incorporate color changes in your programs?
  2197.   When  we  showed  the  "bouncing ball"  program,  you  saw how keyboard
  2198. commands,  like  cursor  movement,  could  be  incorporated  within PRINT
  2199. statements.  In  a like way,  you can also add text color changes to your
  2200. programs.
  2201.   You have a full range of 16 text colors to work with.  Using <CTRL> key
  2202. and a number key, the following colors are available:
  2203.  
  2204.      1        2        3        4        5       6        7        8
  2205.    Black    White     Red     Cyan    Purple   Green    Blue    Yellow
  2206.  
  2207.   If  you  hold  down the <C=> key along with the appropriate number key,
  2208. these additional eight colors can be used:
  2209.  
  2210.      1        2        3        4        5       6        7        8
  2211.    Orange   Brown   Lt.Red    Gray 1  Gray 2  Lt.Green  Lt.Blue  Gray 3
  2212.  
  2213.   Type NEW,  and experiment with the following.  Hold down the <CTRL> key
  2214. and  at  the  same  time hit the <1> key.  Next,  hit the <R> key without
  2215. holding down the <CTRL> key.  Now,  while again depressing the <CTRL> key
  2216. at the same time hit the <2> key.  Release the <CTRL> key and hit the <A>
  2217. key. Move through the numbers, alternating with the letters, and type out
  2218. the word RAINBOW as follows:
  2219.  
  2220.   10 PRINT " R A I N B O W"
  2221.             ^ ^ ^ ^ ^ ^ ^
  2222.      <CTRL><1 2 3 4 5 6 7>
  2223.  
  2224.   RUN
  2225.   RAINBOW
  2226.  
  2227.   Just  as  cursor  controls  show as graphic characters within the quote
  2228. marks of print statements, color controls are also represented as graphic
  2229. characters.
  2230.   In  the  previous  example,  when  you held down <CTRL> and typed <3> a
  2231. "{Pound Sign}"  was displayed.  <CTRL> <7>  displayed a "<-".  Each color
  2232. control  will  display its unique graphic code when used in this way. The
  2233. table shows the graphic representations of each printable color control.
  2234.  
  2235.  
  2236.   KEYBOARD    COLOR      DISPLAY         KEYBOARD    COLOR      DISPLAY
  2237.   ---------------------------------------------------------------------
  2238.   <CTRL><1>   BLACK                      <C=><1>     ORANGE
  2239.   <CTRL><2>   WHITE                      <C=><2>     BROWN
  2240.   <CTRL><3>   RED                        <C=><3>     LT. RED
  2241.   <CTRL><4>   CYAN                       <C=><4>     GRAY 1
  2242.   <CTRL><5>   PURPLE                     <C=><5>     GRAY 2
  2243.   <CTRL><6>   GREEN                      <C=><6>     LT. GREEN
  2244.   <CTRL><7>   BLUE                       <C=><7>     LT. BLUE
  2245.   <CTRL><8>   YELLOW                     <C=><8>     GRAY 3
  2246.  
  2247.   Even  though  the PRINT statement may look a bit strange on the screen,
  2248. when  you RUN the program,  only the text will be displayed.  And it will
  2249. automatically change colors according to the color controls you placed in
  2250. the print statement.
  2251.   Try  a  few examples of your own,  mixing any number of colors within a
  2252. single PRINT statement. Remember, too, you can use the second set of text
  2253. colors by using the Commodore key and the number keys.
  2254.  
  2255. TIP: You will notice after running a program with color or mode (reverse)
  2256. changes, that the "READY." prompt and any additional text you type is the
  2257. same as the last color or mode change. To get back to the normal display,
  2258. remember to depress: <RUN/STOP> and <RESTORE>.
  2259.  
  2260.  
  2261. 5.3. Color CHR$ Codes
  2262.  
  2263.   Take a brief look at Appendix F, then turn back to this section.
  2264.   You may have noticed in looking over the list of CHR$ codes in Appendix
  2265. F  that  each  color  (as  well as most other keyboard controls,  such as
  2266. cursor movement)  has a unique code.  These codes can be printed directly
  2267. to  obtain the same results as typing CTRL and the appropriate key within
  2268. the PRINT statement.
  2269.   For example, try this:
  2270.  
  2271.   NEW
  2272.   10 PRINT CHR$(147) : REM {CLR/HOME}
  2273.   20 PRINT CHR$(30); "CHR$(30) CHANGES ME TO?"
  2274.  
  2275.   RUN
  2276.   CHR$(30) CHANGES ME TO?
  2277.  
  2278.   The  text should now be green.  In many cases,  using the CHR$ function
  2279. will  be much easier,  especially if you want to experiment with changing
  2280. colors.  The  following  program  is  a different way to get a rainbow of
  2281. colors.  Since  there are a number of lines that are similar (40-110) use
  2282. editing keys to save a lot of typing.  See the notes after the listing to
  2283. refresh your memory on the editing procedures.
  2284.  
  2285.   NEW
  2286.  
  2287.     1 REM AUTOMATIC COLOR BARS
  2288.     5 PRINT CHR$(147) : REM CHR$(147) = CLR/HOME
  2289.    10 PRINT CHR$(18); "     "; : REM REVERSE BAR
  2290.    20 CL = INT(8*RND(1))+1
  2291.    30 ON CL GOTO 40,50,60,70,80,90,100,110
  2292.    40 PRINT CHR$(5); : GOTO 10
  2293.    50 PRINT CHR$(28); : GOTO 10
  2294.    60 PRINT CHR$(30); : GOTO 10
  2295.    70 PRINT CHR$(31); : GOTO 10
  2296.    80 PRINT CHR$(144); : GOTO 10
  2297.    90 PRINT CHR$(156); : GOTO 10
  2298.   100 PRINT CHR$(158); : GOTO 10
  2299.   110 PRINT CHR$(159); : GOTO 10
  2300.  
  2301.   Type lines 1 through 40 normally. Your display should look like this:
  2302.  
  2303.    1 REM AUTOMATIC COLOR BARS
  2304.    5 PRINT CHR$(147) : REM CHR$(147) = CLR/HOME
  2305.   10 PRINT CHR$(18); "     "; : REM REVERSE BAR
  2306.   20 CL = INT(8*RND(1))+1
  2307.   30 ON CL GOTO 40,50,60,70,80,90,100,110
  2308.   40 PRINT CHR$(5); : GOTO 10
  2309.  
  2310. EDITING NOTES
  2311.  
  2312.    Use the  <CRSR UP> key to position the cursor on line 40.  Then type 5
  2313. over the 4 of 40. Next, use the <CRSR RIGHT> key to move over to the 5 in
  2314. the CHR$ parentheses.  Hit <SHIFT> <INST/DEL> to open up a space and type
  2315. '28'. Now just hit <RETURN> with the cursor anywhere on the line.
  2316.   The display should now look like this:
  2317.  
  2318.    1 REM AUTOMATIC COLOR BARS
  2319.    5 PRINT CHR$(147) : REM CHR$(147) = CLR/HOME
  2320.   10 PRINT CHR$(18); "     "; : REM REVERSE BAR
  2321.   20 CL = INT(8*RND(1))+1
  2322.   30 ON CL GOTO 40,50,60,70,80,90,100,110
  2323.   50 PRINT CHR$(28); : GOTO 10
  2324.  
  2325.   Don't worry.  Line 40 is still there.  LIST the program and see.  Using
  2326. the  same  procedure,  continue  to  modify the last line with a new line
  2327. number  and  CHR$  code  until all the remaining lines have been entered.
  2328. See,  we told you the editing keys would come in handy. As a final check,
  2329. list  the entire program to make sure all the lines were entered properly
  2330. before you RUN it.
  2331.   Here is a short explanation of what's going on.
  2332.   You've probably figured out most of the color bar program by now except
  2333. for some strange new statement in line 30. But let's quickly see what the
  2334. whole program actually does. Line 5 prints the CHR$ code for CLR/HOME.
  2335.   Line 10 turns reverse type on and prints 5 spaces, which turn out to be
  2336. a bar, since they're reversed. The first time through the program the bar
  2337. will be light blue, the normal text color.
  2338.   Line 20  uses  our  workhorse,  the  random function to select a random
  2339. color between 1 and 8.
  2340.   Line 30 contains  a  variation  of  the  IF ... THEN statement which is
  2341. called ON ... GOTO.  ON ... GOTO allows the program to choose from a list
  2342. of  line numbers to go to.  If the variable (in this case CL) has a value
  2343. of 1, the first line number is the one chosen (here 40).  If the value is
  2344. 2, the second number in the list is used, etc.
  2345.   Lines 40-110 just convert our random key colors to the appropriate CHR$
  2346. code for that color  and return the program to line 10 to PRINT a section
  2347. of the bar in that color. Then the whole process starts over again.
  2348.   See  if you can figure out how to produce 16 random numbers,  expand ON
  2349. ... GOTO to handle them,  and add the remaining CHR$ codes to display the
  2350. remaining 8 colors.
  2351.  
  2352.  
  2353. 5.4. PEEKs and POKEs
  2354.  
  2355.   No,  we're not talking about jobbing the computer,  but we will be able
  2356. to "look around" inside the machine and "stick" things in there.
  2357.   Just  as  variables  could be thought of as a representation of "boxes"
  2358. within the machine where you placed your information,  you can also think
  2359. of  some  specially  defined  "boxes"  within the computer that represent
  2360. specific memory locations.
  2361.   The  Commodore 64  looks  at  these  memory  locations  to see what the
  2362. screen's background and border color should be, what characters are to be
  2363. displayed on the screen -- and where -- and a host of other tasks.
  2364.   By  placing,  "POKEing",  a  different  value  into  the  proper memory
  2365. location,  we can change colors, define and move objects, and even create
  2366. music.
  2367.   These memory locations could be represented like this:
  2368.  
  2369.   +-----------+     +-----------+      +-----------+      +-----------+
  2370.   |   53280   |     |   53281   |      |   53282   |      |   53283   |
  2371.   |     X     |     |     Y     |      |           |      |           |
  2372.   +-----------+     +-----------+      +-----------+      +-----------+
  2373.  
  2374.      BORDER          BACKGROUND
  2375.      COLOR             COLOR
  2376.  
  2377.   Above  we  showed just four locations,  two of which control the screen
  2378. and background colors. Try typing this:
  2379.  
  2380.   POKE 53281,7 <RETURN>
  2381.  
  2382.   The  background  color  of  the screen will change to yellow because we
  2383. placed the value '7' --  for yellow --  in the location that controls the
  2384. background color of the screen.
  2385.   Try  POKEing  different values into the background color location,  and
  2386. see  what results you get.  You can POKE any value between 0 and 255, but
  2387. only 0 through 15 will work.
  2388.   The actual values to POKE for each color are:
  2389.  
  2390. +-----------------------------------------------------------------------+
  2391. |       0       BLACK                  8        ORANGE                  |
  2392. |       1       WHITE                  9        BROWN                   |
  2393. |       2       RED                   10        Light RED               |
  2394. |       3       CYAN                  11        GRAY 1                  |
  2395. |       4       PURPLE                12        GRAY 2                  |
  2396. |       5       GREEN                 13        Light GREEN             |
  2397. |       6       BLUE                  14        Light BLUE              |
  2398. |       7       YELLOW                15        GRAY 3                  |
  2399. +-----------------------------------------------------------------------+
  2400.  
  2401.   Can  you  think  of  a way to display the various background and border
  2402. combinations? The following may be of some help:
  2403.  
  2404.   NEW
  2405.  
  2406.   10 FOR BA = 0 TO 15
  2407.   20 FOR BO = 0 TO 15
  2408.   30 POKE 53280, BO
  2409.   40 POKE 53281, BA
  2410.   50 FOR X = 1 TO 2000 : NEXT X
  2411.   60 NEXT BO : NEXT BA
  2412.  
  2413.   Two  simple  loops  were  set  up  to POKE various values to change the
  2414. background and border colors. The DELAY loop in line 50 just slows things
  2415. down a bit.
  2416.   For the curious, try:
  2417.  
  2418.   ? PEEK(53280) AND 15
  2419.  
  2420.   You  should get a value of 15.  This is the last value BORDER was given
  2421. and  makes  sense  because both the background and border colors are GRAY
  2422. (value 15) after the program is run.
  2423.   By entering AND 15 you eliminate all other values except 1-15,  because
  2424. of  the  way  color codes are stored in the computer.  Normally you would
  2425. expect  to  find  the  same value that was last POKEd in the location. In
  2426. general,  PEEK lets us examine a specific location  and see what value is
  2427. presently there. Can you think of a one line addition to the program that
  2428. will display the value of BACK and BORDER as the program runs?  How about
  2429. this:
  2430.  
  2431.   25 PRINT CHR$(147); "BORDER =";PEEK(53280) AND 15,
  2432.      "BACKGROUND ="; PEEK(53281) AND 15
  2433.  
  2434.  
  2435. 5.5. Screen Graphics
  2436.  
  2437.   In all the printing information  that you've done so far,  the computer
  2438. normally  handled  information in a sequential fashion:  one character is
  2439. printed after the next, starting from the current cursor position (except
  2440. where you asked for a new line, or used the ',' in PRINT formatting).
  2441.   To PRINT data in a particular spot  you can start from a known place on
  2442. the screen  and PRINT the proper number of cursor controls  to format the
  2443. display. But this takes program steps and is time consuming.
  2444.   But  just  as  there  are certain spots in the Commodore 64's memory to
  2445. control  color,  there  are  also  locations that you can use to directly
  2446. control each location on the screen.
  2447.  
  2448. SCREEN MEMORY MAP
  2449.  
  2450.   Since  the  computer's screen is capable of holding 1000 characters (40
  2451. columns by 25 lines)  there are 1000 memory locations set aside to handle
  2452. what  is placed on the screen.  The layout of the screen could be thought
  2453. of as a grid, with each square representing a memory location.
  2454.   And  since  each location in memory can contain a number from 0 to 255,
  2455. there  are  256  possible  values for each memory location.  These values
  2456. represent  the  different  characters  the  Commodore 64 can display (see
  2457. Appendix E).  By  POKEing  the  value  for a character in the appropriate
  2458. screen  memory  location,  that character will be displayed in the proper
  2459. position.
  2460.   Screen  memory  in  the Commodore 64 normally begins at memory location
  2461. 1024,  and ends at location 2023.  Location 1024 is the upper left corner
  2462. of the screen. Location 1025 is the position of the next character to the
  2463. right  of that,  and so on down the row.  Location 1063 is the right-most
  2464. position of the first row. The next location following the last character
  2465. on a row is the first character on the next row down.
  2466.  
  2467.                                  COLUMN                             1063
  2468.       0             10             20             30            39 /
  2469.      +------------------------------------------------------------/
  2470. 1024 |                                                            |  0
  2471. 1064 |                                                            |
  2472. 1104 |                                                            |
  2473. 1144 |                                                            |
  2474. 1184 |                                                            |
  2475. 1224 |                                                            |
  2476. 1264 |                                                            |
  2477. 1304 |                                                            |
  2478. 1344 |                                                            |
  2479. 1384 |                                                            |
  2480. 1424 |                                                            | 10
  2481. 1464 |                                                            |
  2482. 1504 |                                                            |   ROW
  2483. 1544 |                                                            |
  2484. 1584 |                                                            |
  2485. 1624 |                                                            |
  2486. 1664 |                                                            |
  2487. 1704 |                                                            |
  2488. 1744 |                                                            |
  2489. 1784 |                                                            |
  2490. 1824 |                                                            | 20
  2491. 1864 |                                                            |
  2492. 1904 |                                                            |
  2493. 1944 |                                                            |
  2494. 1984 |                                                            | 24
  2495.      +------------------------------------------------------------\
  2496.                                                                    \
  2497.                                                                     2023
  2498.  
  2499.   Now,  let's  say that you're controlling a ball bouncing on the screen.
  2500. The ball is in the middle of the screen,  column 20, row 12.  The formula
  2501. for calculation of the memory location on the screen is:
  2502.  
  2503.   POINT = 1024 + X + 40 * Y
  2504.                  ^        ^
  2505.                  |        |__ Column
  2506.                  |___________ Row
  2507.  
  2508. where X is the column and Y is the row.
  2509.   Therefore, the memory location of the ball is:
  2510.  
  2511.   1024 + 20 + 480  or  1524
  2512.          ^     ^
  2513.          |     |_____________ Row (40 * 12)
  2514.          |___________________ Column
  2515.  
  2516. Clear the screen with <SHIFT> and <CLR/HOME> and type:
  2517.  
  2518.   POKE 1524, 81
  2519.   POKE 55796, 1
  2520.          ^    ^
  2521.          |    |______ Color
  2522.          |___________ Location
  2523.  
  2524.  
  2525. COLOR MEMORY MAP
  2526.  
  2527.   A ball appears in the middle of the screen! You have placed a character
  2528. directly  into screen memory without using the PRINT statement.  The ball
  2529. that appeared was white. However there is a way to change the color of an
  2530. object on the screen by altering another range of memory. Type:
  2531.  
  2532.   POKE 55796, 2
  2533.          ^    ^
  2534.          |    |______ Color
  2535.          |___________ Location
  2536.  
  2537.   The  ball's color changes to red.  For every spot on the Commodore 64's
  2538. screen  there are two memory locations,  one for the character code,  and
  2539. the  other  for  the color code.  The color memory map begins at location
  2540. 55296 (top left-hand  corner),  and continues on for 1000 locations.  The
  2541. same color codes, from 0-15, that we used to change border and background
  2542. colors can be used here to directly change character colors.
  2543.  
  2544.                                  COLUMN                             55335
  2545.       0             10             20             30            39 /
  2546.      +------------------------------------------------------------/
  2547. 55296|                                                            |  0
  2548. 55336|                                                            |
  2549. 55376|                                                            |
  2550. 55416|                                                            |
  2551. 55456|                                                            |
  2552. 55496|                                                            |
  2553. 55536|                                                            |
  2554. 55576|                                                            |
  2555. 55616|                                                            |
  2556. 55656|                                                            |
  2557. 55696|                                                            | 10
  2558. 55736|                                                            |
  2559. 55776|                                                            |   ROW
  2560. 55816|                                                            |
  2561. 55856|                                                            |
  2562. 55896|                                                            |
  2563. 55936|                                                            |
  2564. 55976|                                                            |
  2565. 56016|                                                            |
  2566. 56056|                                                            |
  2567. 56096|                                                            | 20
  2568. 56136|                                                            |
  2569. 56176|                                                            |
  2570. 56216|                                                            |
  2571. 56256|                                                            | 24
  2572.      +------------------------------------------------------------\
  2573.                                                                    56295
  2574.  
  2575.   The  formula  we  used  for  calculating screen memory locations can be
  2576. modified to give the locations to POKE color codes. The new formula is:
  2577.  
  2578.   COLOR PRINT = 55296 + X + 40 * Y
  2579.  
  2580.  
  2581. 5.6. More Bouncing Balls
  2582.  
  2583.   Here's  a  revised  bouncing  ball  program that prints directly on the
  2584. screen with POKEs, rather than using controls within PRINT statements. As
  2585. you will see after running the program, it is much more flexible than the
  2586. earlier program,  and will lead up to programming much more sophisticated
  2587. animation.
  2588.  
  2589.   NEW
  2590.  
  2591.    10 PRINT "{CLR/HOME}"
  2592.    20 POKE 53280,7 : POKE 53281,13
  2593.    30 X = 1 : Y = 1
  2594.    40 DX = 1 : DY = 1
  2595.    50 POKE 1024 + X + 40 * Y, 81
  2596.    60 FOR T = 1 TO 10 : NEXT
  2597.    70 POKE 1024 + X + 40 * Y, 32
  2598.    80 X = X + DX
  2599.    90 IF X <= 0 OR X >= 39 THEN DX = -DX
  2600.   100 Y = Y + DY
  2601.   110 IF Y <= 0 OR Y >= 24 THEN DY = -DY
  2602.   120 GOTO 50
  2603.  
  2604.   Line 10  clears  the  screen,  and line 20 sets the background to light
  2605. green with a yellow border.
  2606.   The  X  and  Y  variables  in line 30 keep track of the current row and
  2607. column  position of the ball.  The DX and DY variables in line 40 are the
  2608. horizontal  and  vertical direction of the ball's movement.  When a +1 is
  2609. added to the X value,  the ball is moved to the right;  when -1 is added,
  2610. the  ball  moves to the left.  A +1 added to Y moves the ball down a row;
  2611. a -1 added to Y moves the ball up a row.
  2612.   Line 50  puts  the  ball  on the screen at the current cursor position.
  2613. Line 60  is the familiar delay loop,  leaving the ball on the screen just
  2614. long enough to see it.
  2615.   Line 70 erases the ball by putting a space (code 32) where the ball was
  2616. on the screen.
  2617.   Line 80  adds  the  direction factor to X.  Line 90 tests to see if the
  2618. ball  has  reached  one  of  the  side walls,  reversing the direction if
  2619. there's  a  bounce.  Line  100  and 110 do the same thing for the top and
  2620. bottom walls.
  2621.   Line 120 sends the program back to display and moves the ball again.
  2622.   By changing the code in line 50 from 81 to another character code,  you
  2623. can change the ball to any other character.  If you change DX and DY to 0
  2624. the ball will bounce straight instead of diagonally.
  2625.   We  can also add a little more intelligence.  So far the only thing you
  2626. checked  for  is the X and Y values getting out of bounds for the screen.
  2627. Add the following lines to the program:
  2628.  
  2629.    21 FOR L = 1 TO 10
  2630.    25 POKE 1024 + INT(RND(1)*1000), 166   <------------------ Screen Code
  2631.    27 NEXT L
  2632.    85 IF PEEK(1024 + X + 40 * Y) = 166 THEN DX = -DX : GOTO 80
  2633.   105 IF PEEK(1024 + X + 40 * Y) = 166 THEN DY = -DY : GOTO 100
  2634.  
  2635.   Lines  21  to 27 put 10 blocks on the screen in random positions. Lines
  2636. 85  and  105  check  (PEEK)  to see if the ball is about to bounce into a
  2637. block, and changes the ball's direction if so.
  2638.  
  2639.  
  2640.  
  2641. 6. SPRITE GRAPHICS
  2642.  
  2643.  
  2644. 6.1. Introduction to Sprites
  2645.  
  2646.   In previous chapters dealing with graphics, we saw that graphic symbols
  2647. could be used in PRINT statements  to create animation  and add chartlike
  2648. appearances to our display.
  2649.   A way was also shown  to POKE character codes in specific screen memory
  2650. locations.  This  would then place the appropriate characters directly on
  2651. the screen in the right spot.
  2652.   Creating  animation  in both these cases requires a lot of work because
  2653. objects must be created from existing graphic symbols.  Moving the object
  2654. requires  a  number of program statements to keep track of the object and
  2655. move  it  to  new spot.  And,  because of the limitation of using graphic
  2656. symbols,  the  shape and resolution of the object might not be as good as
  2657. required.
  2658.   Using sprites in animated sequences eliminates a lot of these problems.
  2659. A  sprite  is a high-resolution programmable object that can be made into
  2660. just about any shape -- through BASIC commands.  The object can be easily
  2661. moved  around  the screen by simply telling the computer the position the
  2662. sprite should be moved to. The computer takes care of the rest.
  2663.   And  sprites  have  much more power than just that.  Their color can be
  2664. changed;  you  can tell if one object collides with another;  they can be
  2665. made  to go in front and behind another;  and they can be easily expanded
  2666. in size, just for starters.
  2667.   The  penalty for all this is minimal.  However,  using sprites requires
  2668. knowing  some  more  details  about how the Commodore 64 operates and how
  2669. numbers  are  handled  within  the computer.  It's not as difficult as it
  2670. sounds,  though.  Just follow the examples  and you'll be making your own
  2671. sprites do amazing things in no time.
  2672.  
  2673.  
  2674. 6.2. Sprite Creation
  2675.  
  2676.   Sprites are controlled by a separate picture-maker in the Commodore 64.
  2677. This  picture maker handles the video display.  It does all the hard work
  2678. of  creating  and  keeping  track  of  characters and graphics,  creating
  2679. colors, and moving around.
  2680.   This display circuit has 46 different "ON/OFF" locations which act like
  2681. internal  memory  locations.  Each  of these locations breaks down into a
  2682. series of 8 blocks. And each block can either be "ON" or "OFF". We'll get
  2683. into  more  detail  about this later.  By POKEing the appropriate decimal
  2684. value  in  the  proper  memory location you can control the formation and
  2685. movement of your sprite creations.
  2686.   In  addition  to accessing many of the picture making locations we will
  2687. also be using some of the Commodore 64's main memory to store information
  2688. (data) that defines the sprites. Finally, eight memory locations directly
  2689. after  the  screen memory will be used to tell the computer exactly which
  2690. memory area each sprite will get its data from.
  2691.   As   we   go   through   some  examples,   the  process  will  be  very
  2692. straightforward, and you'll get the hang of it.
  2693.   So let's get on with creating some sprite graphics.  A sprite object is
  2694. 24 dots wide by 21 dots long.  Up to eight sprites can be controlled at a
  2695. time.  Sprites are displayed in a special independent 320 dot wide by 200
  2696. dot  high  area.  However,  you can use your sprite with any mode,  high-
  2697. resolution, low-resolution, text etc.
  2698.   Say you want to create a balloon and have it float around the sky.  The
  2699. balloon could be designed as in the 24 by 21 grid:
  2700.  
  2701.  
  2702.                           SERIES |SERIES |SERIES
  2703.                              1   |   2   |   3
  2704.                                  |       |
  2705.                           1       1       1
  2706.                           2631    2631    2631
  2707.                           842684218426842184268421
  2708.                          +------------------------+
  2709.                        1 |.........#######........|
  2710.                        2 |.......###########......|
  2711.                        3 |......#############.....|
  2712.                        4 |......#####...#####.....|
  2713.                        5 |.....#####.###..####....|
  2714.                        6 |.....#####.###.#####....|
  2715.                        7 |.....#####.###..####....|
  2716.                        8 |......#####...#####.....|
  2717.                        9 |......#############.....|
  2718.                    R  10 |......#############.....|
  2719.                    O  11 |......#.#########.#.....|
  2720.                    W  12 |.......#.#######.#......|
  2721.                       13 |.......#..#####..#......|
  2722.                       14 |........#..###..#.......|
  2723.                       15 |........#..###..#.......|
  2724.                       16 |.........#..#..#........|
  2725.                       17 |.........#..#..#........|
  2726.                       18 |..........#####.........|
  2727.                       19 |..........#####.........|
  2728.                       20 |..........#####.........|
  2729.                       21 |...........###..........|
  2730.                          +------------------------+
  2731.                                    1    1    2   2
  2732.                           1   5    0    5    0   4
  2733.  
  2734.                                    COLUMN
  2735.  
  2736.   The  next  step is to convert the graphic design into data the computer
  2737. can use.  Get a piece of notebook or graph paper and set up a sample grid
  2738. that  is  21 spaces down and 24 spaces across.  Across the top write 128,
  2739. 64,  32,  16,  8,  4,  2,  1,  three  times (as shown) for each of the 24
  2740. squares.  Number down the left side of the grid 1-21 for each row.  Write
  2741. the  word  DATA  at  the  end  of each row. Now fill in the grid with any
  2742. design or use the balloon that we have. It's easiest to outline the shape
  2743. first and then go back and fill in the grid.
  2744.   Now  if  you  think  of  all  the  squares  you  filled in as "ON" then
  2745. substitute  a 1 for each filled square.  For the one's that aren't filled
  2746. in, they're "OFF" so put a zero.
  2747.   Starting  on  the  first  row,  you need to convert the dots into three
  2748. separate  pieces of data the computer can read.  Each set of 8 squares is
  2749. equal to one piece of data called a byte in our balloon. Working from the
  2750. left,  the first 8 squares are blank, or 0,  so the value for that series
  2751. of numbers is 0.
  2752.   The  middle series looks like this  (again a 1 indicates a dot,  0 is a
  2753. space):
  2754.  
  2755.               128    64    32    16    8     4     2     1
  2756.             +-----+-----+-----+-----+-----+-----+-----+-----+
  2757.             |  0  |  1  |  1  |  1  |  1  |  1  |  1  |  1  |
  2758.             +-----+-----+-----+-----+-----+-----+-----+-----+
  2759.                ^     ^     ^     ^     ^     ^     ^     ^
  2760.                |     |     |     |     |     |     |     |
  2761.                0  +  64 +  32 +  16 +  8  +  4  +  2  +  1  =  127
  2762.  
  2763.  
  2764.   The  third  series  on  the first row also contains blanks, so it, too,
  2765. equals zero. Thus, the data for the first line is:
  2766.  
  2767.                              DATA 0, 127, 0
  2768.  
  2769.   The series that make up row two are calculated like this:
  2770.  
  2771.             +-----+-----+-----+-----+-----+-----+-----+-----+
  2772.   Series 1: |  0  |  0  |  0  |  0  |  0  |  0  |  0  |  1  |
  2773.             +-----+-----+-----+-----+-----+-----+-----+-----+
  2774.                                                          1  =  1
  2775.  
  2776.             +-----+-----+-----+-----+-----+-----+-----+-----+
  2777.   Series 2: |  1  |  1  |  1  |  1  |  1  |  1  |  1  |  1  |
  2778.             +-----+-----+-----+-----+-----+-----+-----+-----+
  2779.                ^     ^     ^     ^     ^     ^     ^     ^
  2780.                |     |     |     |     |     |     |     |
  2781.               128 +  64 +  32 +  16 +  8  +  4  +  2  +  1  =  255
  2782.  
  2783.             +-----+-----+-----+-----+-----+-----+-----+-----+
  2784.   Series 3: |  1  |  1  |  0  |  0  |  0  |  0  |  0  |  0  |
  2785.             +-----+-----+-----+-----+-----+-----+-----+-----+
  2786.                ^     ^
  2787.                |     |
  2788.               128 +  64                                     =  192
  2789.  
  2790.   For row 2, the data would be:
  2791.  
  2792.                             DATA 1, 255, 192
  2793.  
  2794.   In the same way, the three series that make up each remaining row would
  2795. be converted into their decimal value.  Take the time to do the remainder
  2796. of the conversion in this example.
  2797.   Now  that you have the data for your object,  how can it be put to use?
  2798. Type in the following program and see what happens.
  2799.  
  2800.    1 REM UP, UP, AND AWAY!
  2801.    5 PRINT "{CLR/HOME}"
  2802.   10 V = 53248  : REM START OF DISPLAY CHIP
  2803.   11 POKE V+21, 4  : REM ENABLE SPRITE 2
  2804.   12 POKE 2042, 13  : REM SPRITE 2 DATA FROM 13TH BLOCK
  2805.   20 FOR N = 0 TO 62  : READ Q : POKE 832+N, Q : NEXT
  2806.   30 FOR X = 0 TO 200        ^------ GETS ITS INFO. FROM DATA*
  2807.   40 POKE V+4, X  : REM UPDATE X COORDINATES
  2808.   50 POKE V+5, X  : REM UPDATE Y COORDINATES
  2809.   60 NEXT X
  2810.   70 GOTO 30
  2811.  200 DATA 0,127,0,1,255,192,3,255,224,3,231,224 <- INFO. READ IN FROM "Q"
  2812.  210 DATA 7,217,240,7,223,240,7,217,240,3,231,224
  2813.  220 DATA 3,255,224,3,255,224,2,255,160,1,127,64
  2814.  230 DATA 1,62,64,0,156,128,0,156,128,0,73,0,0,73,0
  2815.  240 DATA 0,62,0,0,62,0,0,62,0,0,28,0
  2816.  
  2817.   * FOR MORE DETAIL ON READ & DATA SEE CHAPTER 8.
  2818.  
  2819.   If  you  typed  everything  correctly,  your balloon is smoothly flying
  2820. across the sky:
  2821.  
  2822.   [ PICTURE OMITTED ]
  2823.  
  2824.   In  order  to  understand  what  happened,  first you need to know what
  2825. picture making locations control the functions you need. These locations,
  2826. called registers, could be illustrated in this manner:
  2827.  
  2828.   Register(s)   Description
  2829.  
  2830.    0            X coordinate of sprite 0
  2831.    1            Y coordinate of sprite 0
  2832.    2 - 15       Paired like 0 and 1 for sprites 1-7
  2833.   16            Most Significant Bit -- X coordinate
  2834.   21            Sprite appear: 1 = appear, 0 = disappear
  2835.   29            Expand sprite in "X" Direction
  2836.   23            Expand sprite in "Y" Direction
  2837.   39-46         Sprite 0-7 color
  2838.  
  2839.   In  addition  to  this  information you need to know from which 64 byte
  2840. section sprites will get their data (1 byte is used).
  2841.   This data is handled by 8 locations directly after screen memory:
  2842.  
  2843.         +------+------+------+------+------+------+------+------+
  2844.         | 2040 | 2041 | 2042 | 2043 | 2044 | 2045 | 2046 | 2047 |
  2845.         +------+------+------+------+------+------+------+------+
  2846.             ^      ^      ^      ^      ^      ^      ^      ^
  2847.             |      |      |      |      |      |      |      |
  2848.      SPRITE 0      1      2      3      4      5      6      7
  2849.  
  2850.   Now let's outline the exact procedure to get things moving  and finally
  2851. write a program.
  2852.   There  are  only a few things necessary to actually create  and move an
  2853. object.
  2854.  
  2855.   1. Make the proper sprite(s) appear on the screen by POKEing into
  2856.      location 21 a 1 for the bit which turns on the sprite.
  2857.   2. Set sprite pointer (locations 2040-2047) to where sprite data should
  2858.      be read from.
  2859.   3. POKE actual data into memory.
  2860.   4. Through a loop, update X and Y coordinates to move sprite around.
  2861.   5. You can, optionally, expand the object, change colors,  or perform a
  2862.      variety  of  special  functions.  Using  location  29 to expand your
  2863.      sprite in the "X" direction and location 23 in the "Y" direction.
  2864.  
  2865.   There are only a few items in the program that might not be familiar
  2866. from the discussion so far.
  2867.  
  2868.   In line 10,
  2869.   V = 53248
  2870.  
  2871. sets V to the starting memory location of the video chip.  In this way we
  2872. just  increase  V by the memory number to get the actual memory location.
  2873. The register numbers are the ones given on the sprite register map.
  2874.  
  2875.   In line,
  2876.   POKE V+21,4
  2877.  
  2878. makes  sprite 2 appear by placing a 4 in what is called the sprite enable
  2879. register (21) to turn on sprite 2. Think of it like this:
  2880.  
  2881.                                  SPRITES
  2882.  
  2883.                    Decimal Values of Each Sprite Number
  2884.        128      64      32      16      8       4       2       1
  2885.  
  2886.                            Sprite Level Numbers
  2887.         7       6       5       4       3       2       1       0
  2888.     +-------+-------+-------+-------+-------+-------+-------+-------+
  2889.  21 |   0   |   0   |   0   |   0   |   0   |   1   |   0   |   0   | = 4
  2890.     +-------+-------+-------+-------+-------+-------+-------+-------+
  2891.                                                 ^
  2892.                                                 |
  2893.                                  Put a 1 For The SPRITE You Want
  2894.  
  2895.   Each sprite level is represented in section 21 of the sprite memory and
  2896. 4 happens to be sprite level 2. If you were using level 3 you would put a
  2897. 1 in sprite 3 which has a value of 8. In fact, if you used both sprites 2
  2898. and  3 you would put a 1 in both 4 and 8.  You would then add the numbers
  2899. together just like you did with the DATA on your graph paper. So, turning
  2900. on sprites 2 and 3 would be represented as V+21,12.
  2901.  
  2902.   In line 12,
  2903.   POKE 2042,13
  2904.  
  2905. instructs  the computer to get the data for sprite 2 (location 2042) from
  2906. the  13th area of memory.  You know from making your sprite that it takes
  2907. up 63 sections of memory. You may not have realized it, but those numbers
  2908. you put across the top of your grid equal what is known as 3 bytes of the
  2909. computer.  In other words each collection of the following numbers,  128,
  2910. 64, 32, 16, 8, 4, 2, equals 1 byte of computer memory. Therefore with the
  2911. 21 rows of your grid times the 3 bytes of each row,  each sprite takes up
  2912. 63 bytes of memory.
  2913.  
  2914.   20 FOR N = 0 TO 62 : READ Q : POKE 832+N, Q : NEXT
  2915.                             ^               ^
  2916.                             |               |
  2917.                             +---------------+------- 1 WHOLE SPRITE
  2918.  
  2919.   This  line  handles  the actual sprite collision.  The 63 bytes of data
  2920. that  represent  the  sprite you created are READ in through the loop and
  2921. POKEd into the 13th block of memory. This starts at location 832.
  2922.  
  2923.   30 FOR X = 0 TO 200
  2924.   40 POKE V+4, X  <---- SPRITE 2'S X COORDINATE
  2925.   50 POKE V+5, X  <---- SPRITE 2'S Y COORDINATE
  2926.  
  2927.   If  you  remember  from  school  the X coordinate represents an objects
  2928. horizontal movement across the screen and the Y coordinate represents the
  2929. sprite's vertical movement across the screen.  Therefore as the values of
  2930. X change in line 30 from 0 to 200 (one number at a time) the sprite moves
  2931. across  the  screen  DOWN and TO THE RIGHT one space for each number. The
  2932. numbers  are READ by the computer fast enough to make the movement appear
  2933. to be continuous,  instead of 1 step at a time.  If you need more details
  2934. take a look at the register map in Appendix O.
  2935.   When you get into moving multiple objects,  it would be impossible  for
  2936. one  memory  section  to  update  the  locations  of  all  eight objects.
  2937. Therefore  each  sprite  has  its own set of 2 memory sections to make it
  2938. move on the screen.
  2939.   Line 70 starts the cycle over again,  after one pass on the screen. The
  2940. remainder  of  the  program  is  the  data  for  the balloon.  Sure looks
  2941. different on the screen, doesn't it?
  2942.   Now, try adding the following line:
  2943.  
  2944.   25 POKE V+23, 4 : POKE V+29, 4 : REM EXPAND
  2945.  
  2946. and RUN the program again. The balloon has expanded to twice the original
  2947. size!  What we did was simple.  By POKEing 4 (again to indicate sprite 2)
  2948. into  memory  sections  23  and 29,  sprite 2 was expanded in the X and Y
  2949. direction.
  2950.   It's  important  to  note that the sprite will start in the upper left-
  2951. hand corner of the object.  When expanding an object in either direction,
  2952. the starting point remains the same.
  2953.   For some added excitement, make the following changes:
  2954.  
  2955.     11 POKE V+21, 12
  2956.     12 POKE 2042, 13 : POKE 2043, 13
  2957.     30 FOR X = 1 TO 190
  2958.     45 POKE V+6, X
  2959.     55 POKE V+7, 190-X
  2960.  
  2961.   A  second  sprite  (number 3) has been turned on by POKEing 12 into the
  2962. memory location that makes the sprite appear (V+21). The 12 turns sprites
  2963. 3 and 2 on (00001100 = 12).
  2964.   The  added  lines 45 and 55 move sprite 3 around by POKEing values into
  2965. sprite 3's X and Y coordinate locations (V+6 and V+7).
  2966.   Want to fill the sky with even more action? Try making these additions:
  2967.  
  2968.   11 POKE V+21, 28  <-- 28 IS REALLY 4(SPRITE 2)+8(SPRITE 3)+16(SPRITE 4)
  2969.   12 POKE 2042, 13 : POKE 2043, 13 : POKE 2044, 13
  2970.   25 POKE V+23, 12 : POKE V+29, 12
  2971.   48 POKE V+8, X
  2972.   58 POKE V+9, 100
  2973.  
  2974.   In line 11 this time,  another sprite (4) was made to appear by POKEing
  2975. 28  into  the appropriate "ON" location of the sprite memory section. Now
  2976. sprites 2-4 are on (00011100 = 28).
  2977.   Line 12 indicates  that sprite 4 will get its data from the same memory
  2978. area (13th 63 section area) as the other sprites by POKEing 2044,13.
  2979.   In line 25, sprites 2 and 3 are expanded by POKEing 12 (Sprites 2 and 3
  2980. on) into the X and Y direction expanded memory locations (V+23 and V+29).
  2981.   Line 48  moves  sprite  3 along the X axis.  Line 58 positions sprite 3
  2982. halfway  down  the screen,  at location 100.  Because this value does not
  2983. change,  like  it  did  before  with  X=0  to  200,  sprite 3  just moves
  2984. horizontally.
  2985.  
  2986.  
  2987. 6.3. Additional Notes on Sprites
  2988.  
  2989.   Now  that  you've  experimented  with sprites,  a few more words are in
  2990. order.  First,  you can change a sprite's color to any of the standard 16
  2991. color codes (0-15) that were used to change character color. These can be
  2992. found in Chapter 5 or in Appendix G.
  2993.   For example, to change sprite 1 to light green, type:  POKE V+40,13 (be
  2994. sure to set V = 53248).
  2995.   You  may  have  noticed  in  using the example sprite programs that the
  2996. object never moved to the right-hand edge of the screen. This was because
  2997. the screen is 320 dots wide  and the X direction register can only hold a
  2998. value up to 255. How then can you get an object to move across the entire
  2999. screen?
  3000.   There is a location on the memory map  that has not been mentioned yet.
  3001. Location 16  (of the map)  controls something called the Most Significant
  3002. Bit  (MSB) of the sprite's X direction location.  In effect,  this allows
  3003. you to move the sprite to a horizontal spot between 256 and 320.
  3004.   The MSB of X register works like this:  after the sprite has been moved
  3005. to X location 255, place a value into memory location 16 representing the
  3006. sprite  you  want  to  move.  For  example,  to  get  sprite 2 to move to
  3007. horizontal  locations  256-320,  POKE the value for sprite 2 (which is 4)
  3008. into memory location 16:
  3009.  
  3010.   POKE V+16, 4
  3011.  
  3012.   Now  start  from 0 again in the usual X direction register for sprite 2
  3013. (which is in location 4 of the map). Since you are only moving another 64
  3014. spaces, X locations would only range between 0 and 63 this time.
  3015.   This  whole  concept is best illustrated with a version of the original
  3016. BALLOON SPRITE program:
  3017.  
  3018.   10 V = 53248 : POKE V+21, 4 : POKE 2042, 13
  3019.   20 FOR N = 0 TO 62 : READ Q : POKE 832+N, Q : NEXT
  3020.   25 POKE V+5, 100
  3021.   30 FOR X = 0 TO 255
  3022.   40 POKE V+4, X
  3023.   50 NEXT
  3024.   60 POKE V+16, 4
  3025.   70 FOR X = 0 TO 63
  3026.   80 POKE V+4, X
  3027.   90 NEXT
  3028.  100 POKE V+16, 0
  3029.  110 GOTO 30
  3030.  200 DATA 0,127,0,1,255,192,3,255,224,3,231,224
  3031.  210 DATA 7,217,240,7,223,240,7,217,240,3,231,224
  3032.  220 DATA 3,255,224,3,255,224,2,255,160,1,127,64
  3033.  230 DATA 1,62,64,0,156,128,0,156,128,0,73,0,0,73,0
  3034.  240 DATA 0,62,0,0,62,0,0,62,0,0,28,0
  3035.  
  3036.   Line 60  sets  the  most  significant bit for sprite 2.  Line 70 starts
  3037. moving the standard X direction location, moving sprite 2 the rest of way
  3038. across the screen.
  3039.   Line 100 is important because it "TURNS OFF" the MSB so that the sprite
  3040. can start moving from the left edge of the screen again.
  3041.   To  define  multiple  sprites,  you  may need additional blocks for the
  3042. sprite  data.  You  can  use some of BASIC's RAM by moving BASIC.  Before
  3043. typing or loading your program type:
  3044.  
  3045.   POKE 44, 16 : POKE 16*256, 0 : NEW
  3046.  
  3047.   Now, you can use blocks 32 through 41 (locations 2048 through 4095) to
  3048. store sprite data.
  3049.  
  3050.  
  3051. 6.4. Binary Arithmetic
  3052.  
  3053.   It  is  beyond the scope of this introductory manual to go into details
  3054. of how the computer handles numbers. We will, however, provide you with a
  3055. good   base  for  understanding  the  process  and  get  you  started  on
  3056. sophisticated animation.
  3057.   But, before you get too involved we have to define a few terms:
  3058.  
  3059.   BIT -- This is the smallest amount of information a computer can store.
  3060.          Think of a BIT as a switch that is either "ON" or "OFF".  When a
  3061.          BIT  is  "ON" it has a value of 1;  when a BIT is "OFF" it has a
  3062.          value of 0.
  3063.  
  3064. After a BIT, the next level is BYTE.
  3065.  
  3066.   BYTE -- This is defined as a series of BITs. Since a BYTE is made up of
  3067.           8  BITs,  you  can  actually  have  a  total  of  256 different
  3068.           combinations  of  BITs.  In other words,  you can have all BITs
  3069.           "OFF" so your BYTE will look like this:
  3070.  
  3071.           128      64      32      16      8       4       2       1
  3072.        +-------+-------+-------+-------+-------+-------+-------+-------+
  3073.        |   0   |   0   |   0   |   0   |   0   |   0   |   0   |   0   |
  3074.        +-------+-------+-------+-------+-------+-------+-------+-------+
  3075.  
  3076.           and its value will be 0. All BITs "ON" is:
  3077.  
  3078.           128      64      32      16      8       4       2       1
  3079.        +-------+-------+-------+-------+-------+-------+-------+-------+
  3080.        |   1   |   1   |   1   |   1   |   1   |   1   |   1   |   1   |
  3081.        +-------+-------+-------+-------+-------+-------+-------+-------+
  3082.  
  3083.           which is 128+64+32+16+8+4+2+1=255.
  3084.  
  3085. The next step up is called a REGISTER.
  3086.  
  3087.   REGISTER -- Defined as a block of BYTEs strung together.  But,  in this
  3088.               case each REGISTER is really only 1 BYTE long.  A series of
  3089.               REGISTERs makes up a REGISTER MAP. REGISTER MAPS are charts
  3090.               like  the  one  you  looked at to make your BALLOON SPRITE.
  3091.               Each  REGISTER controls a different function,  like turning
  3092.               on  the SPRITE is really called the SPRITE ENABLE REGISTER.
  3093.               Making  the  SPRITE longer is the SPRITE EXPAND X REGISTER,
  3094.               while  making  the  SPRITE  wider  is  the  SPRITE EXPAND Y
  3095.               REGISTER.  Keep  in  mind  that  a  REGISTER is a BYTE that
  3096.               performs a specific task.
  3097.  
  3098. Now let's move on to the rest of BINARY ARITHMETIC.
  3099.  
  3100.                       BINARY TO DECIMAL CONVERSION
  3101.  
  3102. +-----------------------------------------------------------------------+
  3103. |                             Decimal Value                             |
  3104. +-------+-------+-------+-------+-------+-------+-------+-------+-------+
  3105. |  128  |   64  |   32  |   16  |   8   |   4   |   2   |   1   |       |
  3106. +-------+-------+-------+-------+-------+-------+-------+-------+-------+
  3107. |   0   |   0   |   0   |   0   |   0   |   0   |   0   |   1   |  2^0  |
  3108. +-------+-------+-------+-------+-------+-------+-------+-------+-------+
  3109. |   0   |   0   |   0   |   0   |   0   |   0   |   1   |   0   |  2^1  |
  3110. +-------+-------+-------+-------+-------+-------+-------+-------+-------+
  3111. |   0   |   0   |   0   |   0   |   0   |   1   |   0   |   0   |  2^2  |
  3112. +-------+-------+-------+-------+-------+-------+-------+-------+-------+
  3113. |   0   |   0   |   0   |   0   |   1   |   0   |   0   |   0   |  2^3  |
  3114. +-------+-------+-------+-------+-------+-------+-------+-------+-------+
  3115. |   0   |   0   |   0   |   1   |   0   |   0   |   0   |   0   |  2^4  |
  3116. +-------+-------+-------+-------+-------+-------+-------+-------+-------+
  3117. |   0   |   0   |   1   |   0   |   0   |   0   |   0   |   0   |  2^5  |
  3118. +-------+-------+-------+-------+-------+-------+-------+-------+-------+
  3119. |   0   |   1   |   0   |   0   |   0   |   0   |   0   |   0   |  2^6  |
  3120. +-------+-------+-------+-------+-------+-------+-------+-------+-------+
  3121. |   1   |   0   |   0   |   0   |   0   |   0   |   0   |   0   |  2^7  |
  3122. +-------+-------+-------+-------+-------+-------+-------+-------+-------+
  3123.  
  3124.   Using combinations of all eight bits,  you can obtain any decimal value
  3125. from 0 to 255.  Do you start to see  why when we POKEd character or color
  3126. values  into  memory  locations  the values had to be in the 0-255 range?
  3127. Each memory location can hold a byte of information.
  3128.   Any  possible combination of eight 0's and 1's will convert to a unique
  3129. decimal value between 0-255.  If all places contain a 1 then the value of
  3130. the byte equals 255. All zeros equal a byte value zero; "00000011" equals
  3131. 3,  and  so on.  This will be the basis for creating data that represents
  3132. sprites and manipulating them. As just one example, if this byte grouping
  3133. represented part of a sprite (0 is a space, 1 is a colored area):
  3134.  
  3135.         7       6       5       4       3       2       1       0
  3136.        2       2       2       2       2       2       2       2
  3137.    +-------+-------+-------+-------+-------+-------+-------+-------+
  3138.    |   1   |   1   |   1   |   1   |   1   |   1   |   1   |   1   |
  3139.    +-------+-------+-------+-------+-------+-------+-------+-------+
  3140.       128  +   64  +   32  +   16  +   8   +   4   +   2   +   1   =  255
  3141.  
  3142.   Then we would POKE 255 into the appropriate memory location to
  3143. represent that part of the object.
  3144.  
  3145.   TIP:  To save you the trouble of converting binary numbers into decimal
  3146. values  --  we'll need to do that a lot --  the following program will do
  3147. the  work  for  you.  It's  a good idea to enter and save the program for
  3148. future use.
  3149.  
  3150.    5 REM BINARY TO DECIMAL CONVERTER
  3151.   10 INPUT "ENTER 8-BIT BINARY NUMBER :";A$
  3152.   12 IF LEN(A$) <> 8 THEN PRINT "8 BITS PLEASE..." : GOTO 10
  3153.   15 TL = 0 : C = 0
  3154.   20 FOR X = 8 TO 1 STEP -1 : C = C + 1
  3155.   30 TL = TL + VAL(MID$(A$,C,1))*2^(X-1)
  3156.   40 NEXT X
  3157.   50 PRINT A$; " BINARY = "; TL ;" DECIMAL"
  3158.   60 GOTO 10
  3159.  
  3160.   This program  takes your binary number,  which was entered as a string,
  3161. and looks at each character of the string,  from left to right  (the MID$
  3162. function).  The  variable  C  indicates  what character to work on as the
  3163. program goes through the loop.
  3164.   The  VAL  function,  in  line  30,  returns  the  actual  value  of the
  3165. character. Since we are dealing with numeric characters, the value is the
  3166. same  as  the character.  For example,  if the first character of A$ is 1
  3167. then the value would also be 1.
  3168.   The final part of line 30 multiplies the value of the current character
  3169. by  the proper power of 2.  Since the first value is in the 2^7 place, in
  3170. the  example,  TL  would first equal 1 times 128 or 128.  If the bit is 0
  3171. then the value for that place would also be zero.
  3172.   This  process is repeated for all eight characters as TL keeps track of
  3173. the running total decimal value of the binary number.
  3174.  
  3175.  
  3176.  
  3177. 7. CREATING SOUND
  3178.  
  3179.  
  3180. 7.1. Using Sound if You're Not a Computer Programmer
  3181.  
  3182.   Most programmers use computer sound for two purposes:  making music and
  3183. generating  sound  effects.  Before  getting  into  the  "intricacies" of
  3184. programming sound, let's take a quick look at how a typical sound program
  3185. is structured  ...  and give you a short sound program you can experiment
  3186. with.
  3187.  
  3188.  
  3189. 7.2. Structure of a Sound Program
  3190.  
  3191.   To begin with,  there are five settings  which you should know in order
  3192. to generate sound on your COMMODORE 64:  VOLUME,  ATTACK/DECAY,  SUSTAIN/
  3193. RELEASE  (ADSR),  WAVEFORM CONTROL and HIGH FREQUENCY/LOW FREQUENCY.  The
  3194. first  three  settings  are  usually  set  ONCE  at the beginning of your
  3195. program.  The  high  and low frequency settings must be set for EACH NOTE
  3196. you play. The waveform control starts and stops each note.
  3197.  
  3198.  
  3199. 7.3. Sample Sound Program
  3200.  
  3201.   Before you start you have to choose a VOICE.  There are 3 voices.  Each
  3202. voice requires different sound setting numbers for Waveform, etc. You can
  3203. play  1, 2 or 3  voices together but our sample uses only VOICE NUMBER 1.
  3204. Type  in  this program line by line  ...  be sure to hit the <RETURN> key
  3205. after each line:
  3206.  
  3207.   5 FORL=54272TO54296:POKEL,0:NEXT First clear sound chip.
  3208.  10 POKE 54296,15  <-------------- Set VOLUME at highest setting.
  3209.  20 POKE 54277,190 <-------------- Set  ATTACK/DECAY  rates to define how
  3210.                                    fast  a  note  rises to and falls from
  3211.                                    its peak volume level (0 to 255).
  3212.  30 POKE 54278,248 <-------------- Set SUSTAIN/RELEASE to define level to
  3213.                                    prolong note and rate to release it.
  3214.  40 POKE 54273,17 : POKE 54272,37  Find  the not/tone you want to play in
  3215.                                    the TABLE OF MUSICAL NOTES in Appendix
  3216.                                    M  and  enter  the  HIGH-FREQUENCY and
  3217.                                    LOW-FREQUENCY  values  for  that  note
  3218.                                    (each note requires 2 POKEs).
  3219.  50 POKE 54276,17  <-------------- Start  WAVEFORM with one of 4 standard
  3220.                                    settings (17, 33, 65 or 129).
  3221.  60 FOR T = 1 TO 250 : NEXT  <---- Enter a time loop  to set the DURATION
  3222.                                    of  the  note  to be played (a quarter
  3223.                                    note  is  approx. "250"  but  may vary
  3224.                                    since  a longer program can effect the
  3225.                                    timing).
  3226.  70 POKE 54276,16  <-------------- Turn off note.
  3227.  
  3228.   To hear the note you just created,  type the word RUN  and then hit the
  3229. <RETURN> key. To view the program type the word LIST and hit <RETURN>. To
  3230. change it, retype the lines you want to alter.
  3231.  
  3232.  
  3233. 7.4. Making Music on Your Commodore 64
  3234.  
  3235.   You  don't  have to be a musician to make a music on your COMMODORE 64!
  3236. All  you  need  to know are a few simple numbers which tell your computer
  3237. how loud to set the volume,  which notes to play,  how long to play them,
  3238. etc. But first ... here's a program which gives you a quick demonstration
  3239. of  the  COMMODORE 64's incredible music capabilities,  using only ONE of
  3240. your computer's 3 separate voices.
  3241.   Type the word NEW and hit <RETURN> to erase your previous program, then
  3242. enter this program, type the word RUN and hit the <RETURN> key.
  3243.  
  3244.    5 REM MUSICAL SCALE  <---------- Title of program.
  3245.    7 FORL=54272TO54296:POKEL,0:NEXT Clear sound chip.
  3246.   10 POKE 54296,15  <-------------- Sets volume at highest setting (15).
  3247.   20 POKE 54277,9  <--------------- Sets Attack/Decay level (each note).
  3248.   30 POKE 54276,17  <-------------- Determines waveform (type of sound).
  3249.   40 FOR T = 1 TO 300 : NEXT  <---- Duration (how long) each note plays.
  3250.   50 READ A  <--------------------- Reads first number in line 110 DATA.
  3251.   60 READ B  <--------------------- Reads second number in line 110 DATA.
  3252.   70 IF B = -1 THEN END  <--------- ENDs when it READs -1 in line 900.
  3253.   80 POKE 54273, A : POKE 54272, B  POKEs  the  first number from DATA in
  3254.                                     line  110  (A=17)  as  HIGH FREQUENCY
  3255.                                     and  second  number   (B=37)  as  LOW
  3256.                                     FREQUENCY.  Next  time  program loops
  3257.                                     around it READs A as 19  and B as 63,
  3258.                                     and  so  on,  and POKEs these numbers
  3259.                                     into   the  HIGH  and  LOW  FREQUENCY
  3260.                                     locations.  The  number  54273 = HIGH
  3261.                                     FREQUENCY for VOICE 1 and 54272 = LOW
  3262.                                     FREQUENCY for VOICE 1.
  3263.   85 POKE 54276, 17  <------------- Start note.
  3264.   90 FORT=1TO250:NEXT:POKE54276,16  Let it play then stop note.
  3265.   95 FOR T = 1 TO 50 : NEXT  <----- Time for release.
  3266.  100 GOTO 20  <-------------------- Loops back to reset CONTROL  and play
  3267.                                     new note.
  3268.  110 DATA 17,37,19,63,21,154,22,227 Musical  note  values from note value
  3269.  120 DATA25,177,28,214,32,94,34,175 chart  in  Appendix M.  Each  pair of
  3270.                                     numbers  represents  one  note.   For
  3271.                                     example,  17 and 37  represent "C" of
  3272.                                     the 4th octave,  19 and 63  represent
  3273.                                     "D" and so on.
  3274.  900 DATA -1,-1  <----------------- When program reaches -1  it turns off
  3275.                                     HIGH/LOW FREQUENCY settings  and ENDs
  3276.                                     as instructed in line 70.
  3277.  
  3278.   To change the sound to a "harpsichord", change line 85 to read 54276,33
  3279. and line 90 to read FOR T=1 TO 250:NEXT:POKE 54276,32 and RUN the program
  3280. again.  (To change the line,  hit the <RUN/STOP> key to stop the program,
  3281. type word LIST and hit <RETURN>, then retype the program line you want to
  3282. change; the new line will automatically replace the old one). What we did
  3283. here  is change the "waveform" from a "triangular" shaped sound wave to a
  3284. "sawtooth"  wave.  Changing the WAVEFORM can drastically change the sound
  3285. produced by the COMMODORE 64  ... but ... waveform is only one of several
  3286. settings  you  can  change  to  make  different  musical  tones and sound
  3287. effects!  You can also change the ATTACK/DECAY rate of each note  ... for
  3288. example, to change from a "harpsichord" sound to a more "banjo" sound try
  3289. changing lines 20 and 30 to read:
  3290.  
  3291.   20 POKE 54277,3
  3292.   30 POKE 54278,0  <--------------- Sets no sustain for banjo effect.
  3293.  
  3294.   As  you've  just  seen,  you  can  make  your  COMMODORE 64  sound like
  3295. different musical instruments. Let's take a closer look at how each sound
  3296. setting works.
  3297.  
  3298.  
  3299. 7.5. Important Sound Settings
  3300.  
  3301.   1. VOLUME.  --  To  turn on the volume and set it to the highest level,
  3302. type:  POKE 54296,15.  The  volume setting ranges from 0 to 15 but you'll
  3303. use 15 most of the time. To turn "off" the volume, type:
  3304.  
  3305.    POKE 54296,0
  3306.  
  3307.    You only have to set the volume ONCE at the beginning of your program,
  3308. since  the same setting activates all three of the Commodore 64's VOICES.
  3309. (Changing  the  volume  during a musical note or sound effect can produce
  3310. interesting results but is beyond the scope of this introduction.)
  3311.  
  3312.   2. ADSR  and  WAVEFORM  CONTROL  SETTINGS.  --  You've already seen how
  3313. changing  the  waveform  can  change the sound effect from "xylophone" to
  3314. "harpsichord". Each VOICE has its own WAVEFORM CONTROL SETTING which lets
  3315. you define four different types of waveforms:  Triangle,  Sawtooth, Pulse
  3316. (Square)  and  Noise.  The CONTROL also activates the COMMODORE 64's ADSR
  3317. feature, but we'll come back to this in a moment. A sample waveform start
  3318. setting looks like this:
  3319.  
  3320.   POKE 54276,17
  3321.  
  3322. where the first number (54276) represents the control setting for VOICE 1
  3323. and  the  second  number  (17)  represents  the  start  for  a triangular
  3324. waveform.  The settings for each VOICE and WAVEFORM combination are shown
  3325. in the table below.
  3326.  
  3327.                    ADSR AND WAVEFORM CONTROL SETTINGS
  3328.  
  3329.               CONTROL               Note Start/Stop Numbers
  3330.               REGISTER   TRIANGLE     SAWTOOTH     PULSE       NOISE
  3331.  +-----------+---------+-----------+-----------+-----------+-----------+
  3332.  |  VOICE 1  |  54276  |   17/16   |   33/32   |   65/64   |  129/128  |
  3333.  +-----------+---------+-----------+-----------+-----------+-----------+
  3334.  |  VOICE 2  |  54283  |   17/16   |   33/32   |   65/64   |  129/128  |
  3335.  +-----------+---------+-----------+-----------+-----------+-----------+
  3336.  |  VOICE 3  |  54290  |   17/16   |   33/32   |   65/64   |  129/128  |
  3337.  +-----------+---------+-----------+-----------+-----------+-----------+
  3338.  
  3339.   Although  the  control  registers  are  different  for  each  voice the
  3340. waveform settings are the same for each type of waveform. To see how this
  3341. works,  look  at  lines  85 and 90 in the musical scale program.  In this
  3342. program,  immediately after setting the frequency in line 80,  we set the
  3343. CONTROL SETTING for VOICE 1 in line 85  by POKEing 54276,17.  This turned
  3344. on  the  CONTROL  for  VOICE 1 and set it to a TRIANGLE WAVEFORM (17). In
  3345. line  70  we  POKE 54276,16,  stopping  the note.  Later,  we changed the
  3346. waveform  start  setting  from 17 to 33 to create a SAWTOOTH WAVEFORM and
  3347. this gave the scale a "harpsichord" effect.  See  how the CONTROL SETTING
  3348. and  WAVEFORM  interact?  Setting  the waveform is similar to setting the
  3349. volume,  except  each  voice  has its own stetting and instead of POKEing
  3350. volume  levels  we're  defining  waveforms.  Next,  we'll look at another
  3351. aspect of sound ... the ADSR feature.
  3352.  
  3353.   3. ATTACK/DECAY SETTING.  --  As we mentioned before,  the ADSR CONTROL
  3354. SETTING not only defines the waveform but it also activates the ADSR,  or
  3355. ATTACK/DECAY/SUSTAIN/RELEASE feature of the COMMODORE 64.  We'll begin by
  3356. looking  at  the  ATTACK/DECAY  setting.  The  following  chart shows the
  3357. various  ATTACK  and DECAY levels for each voice.  If you're not familiar
  3358. with the concepts of sound attack and decay,  you might think of "attack"
  3359. as the rate at which a note/sound arises to its MAXIMUM VOLUME. The DECAY
  3360. is  the  rate at which the note/sound falls from its highest volume level
  3361. back  to  the  SUSTAIN level.  The following chart shows the ATTACK/DECAY
  3362. setting  for  each  voice,  and  the  numbers  for  each attack and decay
  3363. setting.  Note  that YOU MUST COMBINE ATTACK AND DECAY SETTINGS BY ADDING
  3364. THEN UP AND ENTERING THE TOTAL.  For  example,  you can set a HIGH ATTACK
  3365. rate  and  a  LOW DECAY rate by adding the high attack number (64) to the
  3366. low  decay  number (1).  The total (65) will tell the computer to set the
  3367. high  attack  rate  and  low decay rate. You can also increase the attack
  3368. rates by adding them together (128+64+32+16=MAX. ATTACK RATE of 240).
  3369.  
  3370.                        ATTACK/DECAY RATE SETTINGS
  3371.  
  3372.     ATTACK/DECAY     HIGH  MEDIUM  LOW   LOWEST  HIGH MEDIUM LOW  LOWEST
  3373.    CONTROL  SETTING ATTACK ATTACK ATTACK ATTACK DECAY DECAY DECAY DECAY
  3374.  +---------+-------+------+------+------+------+-----+-----+-----+-----+
  3375.  | VOICE 1 | 54277 |  128 |  64  |  32  |  16  |  8  |  4  |  2  |  1  |
  3376.  +---------+-------+------+------+------+------+-----+-----+-----+-----+
  3377.  | VOICE 2 | 54284 |  128 |  64  |  32  |  16  |  8  |  4  |  2  |  1  |
  3378.  +---------+-------+------+------+------+------+-----+-----+-----+-----+
  3379.  | VOICE 3 | 54291 |  128 |  64  |  32  |  16  |  8  |  4  |  2  |  1  |
  3380.  +---------+-------+------+------+------+------+-----+-----+-----+-----+
  3381.  
  3382.   If  you  set  an attack rate with no decay,  the decay is automatically
  3383. zero, and vice-versa.  For example, if you POKE 54277,64 you set a medium
  3384. attack rate with zero decay for VOICE 1.  If you POKE 54277, 66 you set a
  3385. medium  attack  rate  and a low decay rate (because 66=64+2 and sets BOTH
  3386. settings).  You  can also add up several attack values,  or several decay
  3387. values.  For  example,  you can add a low attack (32) and a medium attack
  3388. (64)  for a combined attack rate of 96,  then add a medium decay of 4 and
  3389. ... presto ... POKE 54277,100.
  3390.   At this point, a sample program will better illustrate the effect. Type
  3391. the word NEW, hit <RETURN> and type in this program and RUN it:
  3392.  
  3393.    5 FOR L=54272 TO 54296:POKE L,0:NEXT  Clear sound chip.
  3394.   10 PRINT "HIT ANY KEY"  <------------- Screen message
  3395.   20 POKE 54296,15  <------------------- Set VOLUME at highest level.
  3396.   30 POKE 54277,64  <------------------- Set Attack/Decay.
  3397.   50 POKE 54273,17 : POKE 54272,37  <--- POKE one note into VOICE 1.
  3398.   60 GET K$ : IF K$ = "" THEN 60  <----- Check the keyboard.
  3399.   70 POKE 54276,17: FOR T=1 TO 200: NEXT Set waveform control (triangle).
  3400.   80 POKE 54276,16: FOR T=1 TO 50: NEXT  Turn off settings.
  3401.   90 GOTO 20  <------------------------- Loop back and do it again.
  3402.  
  3403.   Here,  we're  using  VOICE 1  to create one note at a time  ...  with a
  3404. MEDIUM ATTACK RATE  and  ZERO DECAY.  The  key  is  line 30.  POKEing the
  3405. ATTACK/DECAY  setting  with the number 64 activates a MEDIUM attack rate.
  3406. The  result  sounds like someone bouncing a ball in an oil drum.  Now for
  3407. the fun part.  Hit the <RUN/STOP> key to stop the program,  then type the
  3408. word LIST and hit <RETURN>.  Now type this line and hit <RETURN> (the new
  3409. line 30 automatically replaces the old line 30):
  3410.  
  3411.   30 POKE 54277,190
  3412.  
  3413.   Type  word  RUN  and hit <RETURN> to see how it sounds. What we've done
  3414. here is combine several attack and decay settings. The settings are: HIGH
  3415. ATTACK  (128)  +  LOW ATTACK (32) + LOWEST ATTACK (16) + HIGH DECAY (8) +
  3416. MEDIUM DECAY (4) + LOW DECAY (2) = 190.  This  effect sounds like a sound
  3417. an  oboe  or  other  "reedy"  instrument  might  make.  If  you'd like to
  3418. experiment,  try  changing  the  waveform and attack/decay numbers in the
  3419. musical scale example to see how an "oboe" sounds.  Thus ...  you can see
  3420. that  changing  the  attack/decay  rates  can be used to create different
  3421. types of sound effects.
  3422.  
  3423.   4. SUSTAIN/RELEASE SETTING. --  Like Attack/Decay,  the SUSTAIN/RELEASE
  3424. setting is activated by the ADSR/WAVEFORM CONTROL.  SUSTAIN/RELEASE  lets
  3425. you "extend" (SUSTAIN) a portion of a particular sound, like the "sustain
  3426. pedal"  on  a  piano or organ which lets you prolong a note.  Any note or
  3427. sound  can  be  sustained  at  any one of 16 levels.  The SUSTAIN/RELEASE
  3428. setting  may  be  used with a FOR ... NEXT loop to determine how long the
  3429. note will be held at SUSTAIN volume before being released.  The following
  3430. chart  shows  the  numbers  you  have to POKE to reach different SUSTAIN/
  3431. RELEASE rates.
  3432.  
  3433.                       SUSTAIN/RELEASE RATE SETTINGS
  3434.  
  3435.    SUSTAIN/RELEASE   HIGH  MEDIUM  LOW   LOWEST  HIGH MEDIUM LOW  LOWEST
  3436.    CONTROL  SETTING           SUSTAIN          |        RELEASE
  3437.  +---------+-------+------+------+------+------+-----+-----+-----+-----+
  3438.  | VOICE 1 | 54278 |  128 |  64  |  32  |  16  |  8  |  4  |  2  |  1  |
  3439.  +---------+-------+------+------+------+------+-----+-----+-----+-----+
  3440.  | VOICE 2 | 54285 |  128 |  64  |  32  |  16  |  8  |  4  |  2  |  1  |
  3441.  +---------+-------+------+------+------+------+-----+-----+-----+-----+
  3442.  | VOICE 3 | 54292 |  128 |  64  |  32  |  16  |  8  |  4  |  2  |  1  |
  3443.  +---------+-------+------+------+------+------+-----+-----+-----+-----+
  3444.  
  3445.   As  an  example,  if  you're using VOICE 1,  you can set a HIGH SUSTAIN
  3446. level by typing: POKE 54278,128 or you could combine a HIGH SUSTAIN level
  3447. with a LOW RELEASE rate by adding 128 + 2 and then POKE 54278,130. Here's
  3448. the  same  sample  program  we used in the ATTACK/DECAY section above ...
  3449. with a SUSTAIN/RELEASE feature added. Notice the difference in sounds.
  3450.  
  3451.    5 FOR L=54272 TO 54296:POKE L,0:NEXT  Clear sound chip.
  3452.   10 PRINT "HIT ANY KEY"  <------------- Screen message
  3453.   20 POKE 54296,15  <------------------- Set VOLUME at highest level.
  3454.   30 POKE 54277,64  <------------------- Set Attack/Decay.
  3455.   40 POKE 54278,128 <------------------- Set Sustain/Release.
  3456.   50 POKE 54273,17 : POKE 54272,37  <--- POKE one note into VOICE 1.
  3457.   60 GET K$ : IF K$ = "" THEN 60  <----- Check the keyboard.
  3458.   70 POKE 54276,17: FOR T=1 TO 200: NEXT Set waveform control (triangle).
  3459.   80 POKE 54276,16: FOR T=1 TO 50: NEXT  Turn off settings.
  3460.   90 GOTO 20  <------------------------- Loop back and do it again.
  3461.  
  3462.   In line 30,  we tell the computer to SUSTAIN the note at a HIGH SUSTAIN
  3463. level (128 from chart above) ... after which the tone is released in line
  3464. 80.  You  can vary the duration of a note by changing the "count" in line
  3465. 70.  To see the effect of using the release function try changing line 30
  3466. to POKE 54278,89 (SUSTAIN = 80, RELEASE = 9).
  3467.  
  3468.   5. CHOOSING VOICES AND SETTING HIGH/LOW FREQUENCY SOUND VALUES. -- Each
  3469. individual  note  on the Commodore 64 requires TWO SEPARATE POKE COMMANDS
  3470. ...  one  for  HIGH FREQUENCY and one for LOW FREQUENCY. The MUSICAL NOTE
  3471. VALUE  table  in Appendix M shows you the corresponding POKEs you need to
  3472. play any note in the Commodore 64's eight octave range.  The HIGH and LOW
  3473. FREQUENCY POKE COMMANDS  are  different  for each VOICE you use  --  this
  3474. allows  you to program all 3 voices independently to create 3-voice music
  3475. or exotic sound effects.
  3476.   The  HIGH  and  LOW FREQUENCY POKE COMMANDS for each voice are shown in
  3477. the  chart  below,  which  also  contains  the NOTE VALUES for the middle
  3478. (fifth) octave.
  3479.  
  3480.                               SAMPLE MUSICAL NOTES - FIFTH OCTAVE
  3481. VOICE NUMBER  POKE  +--+--+---+---+--+---+---+--+---+---+---+---+---+---+
  3482. & FREQUENCY   NUMBER| C|C#| D | D#| E| F | F#| G| G#| A | A#| B | C | C#|
  3483. +-------------------+--+--+---+---+--+---+---+--+---+---+---+---+---+---+
  3484. |VOICE 1/HIGH|54273 |34|36| 38| 40|43| 45| 48|51| 54| 57| 61| 64| 68| 72|
  3485. |VOICE 1/LOW |54272 |75|85|126|200|52|198|127|97|111|172|126|188|149|169|
  3486. +-------------------+--+--+---+---+--+---+---+--+---+---+---+---+---+---+
  3487. |VOICE 2/HIGH|54280 |34|36| 38| 40|43| 45| 48|51| 54| 57| 61| 64| 68| 72|
  3488. |VOICE 2/LOW |54279 |75|85|126|200|52|198|127|97|111|172|126|188|149|169|
  3489. +-------------------+--+--+---+---+--+---+---+--+---+---+---+---+---+---+
  3490. |VOICE 3/HIGH|54287 |34|36| 38| 40|43| 45| 48|51| 54| 57| 61| 64| 68| 72|
  3491. |VOICE 3/LOW |54286 |75|85|126|200|52|198|127|97|111|172|126|188|149|169|
  3492. +-------------------+--+--+---+---+--+---+---+--+---+---+---+---+---+---+
  3493.  
  3494.   As you can see,  there are 2 settings for each voice,  a HIGH FREQUENCY
  3495. setting  and  a LOW FREQUENCY setting.  To play a musical note,  you must
  3496. POKE  a  value  into  the HIGH FREQUENCY location and POKE another values
  3497. into  the  LOW FREQUENCY  location.  Using  the  settings  in  our VOICE/
  3498. FREQUENCY/NOTE VALUE  table,  here's the setting that plays a C note from
  3499. the 5th octave (VOICE 1):
  3500.  
  3501.   POKE 54273,34 : POKE 54272,75
  3502.  
  3503. The same note on VOICE 2 would be:
  3504.  
  3505.   POKE 54280,34 : POKE 54279,75
  3506.  
  3507. Used in a program, it looks like this:
  3508.  
  3509.    5 FORL=54272TO54296:POKEL,0:NEXT  Clear sound chip.
  3510.   10 V=54296:W=54276:A=54277:  <---- Set numbers equal to letters.
  3511.      S=54278:H=54273:L=54272
  3512.   20 POKE V,15:POKE A,190:POKE S,89  POKE volume, waveform, attack/decay.
  3513.   30 POKE H,34:POKE L,75  <--------- POKE hi/lo freq. notes.
  3514.   40 POKE W,33:FOR T=1 TO 200:NEXT   Start note, let it play.
  3515.   50 POKE W,32  <------------------- Stop note.
  3516.  
  3517.  
  3518. 7.6. Playing a Song on the Commodore 64
  3519.  
  3520.   The  following  program  can  be  used to compose or play a song (using
  3521. VOICE 1).  There are two important lessons in this program:  first,  note
  3522. how  we  abbreviate all the long control numbers in the first line of the
  3523. program ... after that, we can use the letter W for "Waveform" instead of
  3524. the number 54276.
  3525.   The second lesson concerns the way we use the DATA. This program is set
  3526. up  to  let  you  enter 3 numbers for each note:  the HIGH FREQUENCY NOTE
  3527. VALUE,  the  LOW FREQUENCY NOTE VALUE,  and the DURATION THE NOTE will be
  3528. played.
  3529.   For  this  song,  we used a duration "count" of 125 for an eighth note,
  3530. 250  for  a quarter note,  375 for a dotted quarter note,  500 for a half
  3531. note  and 1000 for a whole note.  These number values can be increased or
  3532. decreased to match a particular tempo, or your own musical taste.
  3533.   To see how a song gets entered, look at line 100.  We entered 34 and 75
  3534. as  our  HIGH  and  LOW FREQUENCY  settings  to play a "C" note (from the
  3535. sample  scale  shown  previously)  and  then the number 250 for a quarter
  3536. note.  So the first note in our song is a quarter note C. The second note
  3537. is also a quarter note,  this time the note is "E"  ...  and so on to the
  3538. end of our tune.  You can enter almost any song this way,  adding as many
  3539. DATA statement lines as you need.  You can continue the note and duration
  3540. numbers  from one line to the next but each line must begin with the word
  3541. DATA.  DATA -1,-1,-1  should be the last line in your program.  This line
  3542. "ends" the song.
  3543.   Type  the  word  NEW  to  erase  your  previous program and type in the
  3544. following program, then type RUN to hear the song.
  3545.  
  3546.   MICHAEL ROW  THE BOAT ASHORE-1 MEASURE
  3547.  
  3548.    2 FOR L = 54272 TO 54296 : POKE L,0 : NEXT
  3549.    5 V=54296:W=54276:A=54277:HF=54273:LF=54272:S=54278:PH=54275:PL=54274
  3550.   10 POKE V,15 : POKE A,88 : POKE PH,15 : POKE PL,15 : POKE S,89
  3551.   20 READ H : IF H = -1 THEN END
  3552.   30 READ L
  3553.   40 READ D
  3554.   60 POKE HF,H : POKE LF,L : POKE W,65
  3555.   80 FOR T = 1 TO D : NEXT : POKE W,64
  3556.   85 FOR T = 1 TO 50 : NEXT
  3557.   90 GOTO 10
  3558.  100 DATA 34,75,250,43,52,250,51,97,375,43,52,125,51,97
  3559.  105 DATA 250,57,172,250
  3560.  110 DATA 51,97,500,0,0,125,43,52,250,51,97,250,57,172
  3561.  115 DATA 1000,51,97,500
  3562.  120 DATA -1,-1,-1
  3563.  
  3564.  
  3565. 7.7. Creating Sound Effects
  3566.  
  3567.   Unlike  music,  sound  effects  are  more  often  tied  to  a  specific
  3568. programming "action" such as the explosion made by an astro-fighter as it
  3569. crashes through a barrier in a space game  ... or the warning buzzer in a
  3570. business  program  that  tells  the  user he's about to erase his disk by
  3571. mistake.
  3572.   You  have  a  wide  range  of  options available  if you want to create
  3573. different sound effects.  Here are 10 programming ideas  which might help
  3574. you get started experimenting with sound effects:
  3575.  
  3576.   1. Change the volume while a note is playing,  for example to create an
  3577.      "echo" effect.
  3578.   2. Vary between two notes rapidly to create a sound "tremor."
  3579.   3. Waveform ... try different settings for each voice.
  3580.   4. Attack/Decay  ...  to alter the rate a sound rises toward its "peak"
  3581.      volume and rate it diminishes from that peak.
  3582.   5. Sustain/Release  ...  to change sustain to volume of a sound effect,
  3583.      and rate it diminishes from that volume.
  3584.   6. Multivoice effects ... playing more than one voice at the same time,
  3585.      each voice independently controlled,  or one voice playing longer or
  3586.      shorter then another, or serving as an "echo" or response to a first
  3587.      note.
  3588.   7. Changing notes on the scale,  or changing octaves,  using the values
  3589.      in the MUSICAL NOTE VALUE table.
  3590.   8. Use  the  Square Waveform  and  different  Pulse Settings  to create
  3591.      different effects.
  3592.   9. Use the Noise Waveform to generate "white noise" for accenting tonal
  3593.      sound effects or creating explosions,  gunshots  or  footsteps.  The
  3594.      same musical notes that create music can also be used with the Noise
  3595.      Waveform to create different types of white noise.
  3596.  10. Combine  several  HIGH/LOW  frequencies  in  rapid succession across
  3597.      different octaves.
  3598.  11. Filter ... try the extra POKE setting in Appendix M.
  3599.  
  3600.  
  3601. 7.8. Sample Sound Effects To Try
  3602.  
  3603.   The  following  programs may be added to almost any BASIC program. They
  3604. are  included  to  give  you  some  programming ideas and demonstrate the
  3605. Commodore 64's sound effect range.
  3606.   Notice  the  programming  shortcut  we're  using  in  line  10.  We can
  3607. abbreviate  those  long cumbersome sound setting numbers by defining them
  3608. as  easy-to-use  letters  (numeric variables).  Line 10 simply means that
  3609. these easy to remember LETTERS can be used instead of those long numbers.
  3610. Here,  V=Volume, W=Waveform,  A=Attack/Decay, H=High Frequency (VOICE 1),
  3611. and  L=Low Frequency  (VOICE 1).  We  then  use  these letters instead of
  3612. numbers in our program ... making our program shorter, typing faster, and
  3613. the sound settings easier to remember and spot.
  3614.  
  3615. DOLL CRYING
  3616.  
  3617.   10 V=54296 : W=54276 : A=54277 : H=54273 : L=54272
  3618.   20 POKE V,15 : POKE W,65 : POKE A,15
  3619.   30 FOR X = 200 TO 5 STEP -2 : POKE H,40 : POKE L,X : NEXT
  3620.   40 FOR X = 150 TO 5 STEP -2 : POKE H,40 : POKE L,X : NEXT
  3621.   50 POKE W,0
  3622.  
  3623. SHOOTING SOUND ... USING VOICE 1, NOISE WAVEFORM, FADING VOLUME
  3624.  
  3625.   10 V=54296 : W=54276 : A=54277 : H=54273 : L=54272
  3626.   20 FOR X = 15 TO 0 STEP -1 : POKE V,X : POKE W,129:
  3627.      POKE A,15 : POKE H,40 : POKE L,200 : NEXT
  3628.   30 POKE W,0 : POKE A,0
  3629.  
  3630.  
  3631.  
  3632. 8. ADVANCED DATA HANDLING
  3633.  
  3634.  
  3635. 8.1. READ and DATA
  3636.  
  3637.   You've  seen  how  to  assign  values  to variables directly within the
  3638. program (A = 2),  and how to assign different values while the program is
  3639. running -- through the INPUT statement.
  3640.   There are many times, though, when neither one of these ways will quite
  3641. fit  the  job  you're  trying  to do,  especially if it involves a lot of
  3642. information.
  3643.   Try this short program:
  3644.  
  3645.   10 READ X
  3646.   20 PRINT "X IS NOW :"; X
  3647.   30 GOTO 10
  3648.   40 DATA 1, 34, 10.5, 16, 234.56
  3649.  
  3650.   RUN
  3651.   X IS NOW : 1
  3652.   X IS NOW : 34
  3653.   X IS NOW : 10.5
  3654.   X IS NOW : 16
  3655.   X IS NOW : 234.56
  3656.   ?OUT OF DATA ERROR IN 10
  3657.   READY.
  3658.   _
  3659.  
  3660.   In  line  10,  the computer READs one value from the DATA statement and
  3661. assigns that value to X. Each time through the loop the next value in the
  3662. DATA  statement  is  read  and  that value assigned to X, and PRINTed.  A
  3663. pointer  in  the computer itself keeps track of which value is to be used
  3664. next:
  3665.  
  3666.           Pointer
  3667.              |
  3668.   40 DATA 1, 34, 10.5, 16, 234.56
  3669.  
  3670.   When all the values have been used,  and the computer executed the loop
  3671. again,  looking  for  another value,  the OUT OF DATA ERROR was displayed
  3672. because there were no more values to READ.
  3673.   It is important to follow the format of the DATA statement precisely:
  3674.  
  3675.   40 DATA 1, 34, 10.5, 16, 234.56
  3676.            ^                     ^
  3677.            |                     |
  3678.     Comma Separates          No Comma
  3679.        Each Item
  3680.  
  3681.   Data statements can contain integer numbers,  real numbers (234.5),  or
  3682. numbers  expressed  in  scientific  notation.  But  you  can't READ other
  3683. variables,  or  have  arithmetic operations in DATA lines.  This would be
  3684. incorrect:
  3685.  
  3686.   40 DATA A, 23/56, 2*5
  3687.  
  3688.   You can,  however,  use a string variable in a READ statement  and then
  3689. place string information in the DATA line. The following is acceptable:
  3690.  
  3691.   NEW
  3692.  
  3693.   10 FOR X = 1 TO 3
  3694.   15 READ A$
  3695.   20 PRINT "A$ IS NOW : "; A$
  3696.   30 NEXT
  3697.   40 DATA THIS, IS, FUN
  3698.  
  3699.   RUN
  3700.   A$ IS NOW : THIS
  3701.   A$ IS NOW : IS
  3702.   A$ IS NOW : FUN
  3703.   READY.
  3704.  
  3705.   Notice  that this time,  the READ statement was placed inside a FOR ...
  3706. NEXT  loop.  This loop was then executed to match the number of values in
  3707. the data statement.
  3708.   In  many  cases  you  will  change  the  number  of  values in the DATA
  3709. statement  each  time  the  program  is run.  A way to avoid counting the
  3710. number  of  values  and  still  avoid  an OUT OF DATA ERROR is to place a
  3711. "FLAG"  as  the  last value in the DATA line.  This would be a value that
  3712. your data would never equal, such as a negative number or a very large or
  3713. small number. When that value is READ the program will branch to the next
  3714. part.
  3715.   There  is  a  way  to  reuse  the  same  DATA  later  in the program by
  3716. RESTOREing  the data pointer to the beginning of the data list.  Add line
  3717. 50 to the previous program:
  3718.  
  3719.   50 GOTO 10
  3720.  
  3721.   You  will  still  get  the  OUT OF DATA ERROR  because  as  the program
  3722. branches back to line 10  to reread the data,  the data pointer indicates
  3723. all the data has been used. Now, add:
  3724.  
  3725.   45 RESTORE
  3726.  
  3727. and  RUN  the  program again.  The data pointer has been RESTOREd and the
  3728. data can be READ continuously.
  3729.  
  3730.  
  3731. 8.2. Averages
  3732.  
  3733.   The following program illustrates a practical use of READ and DATA,  by
  3734. reading in a set of numbers and calculating their average:
  3735.  
  3736.   NEW
  3737.  
  3738.    5 T = 0 : CT = 0
  3739.   10 READ X
  3740.   20 IF X = -1 THEN 50 : REM CHECK FOR FLAG
  3741.   25 CT = CT + 1
  3742.   30 T= T + X : REM UPDATE TOTAL
  3743.   40 GOTO 10
  3744.   50 PRINT "THERE WERE"; CT ;"VALUES READ"
  3745.   60 PRINT "TOTAL ="; T
  3746.   70 PRINT "AVERAGE ="; T/CT
  3747.   80 DATA 75, 80, 62, 91, 87, 93, 78, -1
  3748.  
  3749.   RUN
  3750.   THERE WERE 7 VALUES READ
  3751.   TOTAL = 566
  3752.   AVERAGE = 80.8571429
  3753.  
  3754.   Line 5 sets CT, the CounTer, and T, Total, equal to zero. Line 10 READs
  3755. a value and assigns the value to X. Line 20 checks to see if the value is
  3756. our flag (here a -1).  If the value READ is part of the valid DATA, CT is
  3757. incremented by 1 and X is added to the total.
  3758.   When the flag is READ, the program branches to line 50 which PRINTs the
  3759. number of values read.  Line 60 PRINTs the total, and line 70 divides the
  3760. total by the number of values to get the average.
  3761.   By  using  a  flag at the end of the DATA,  you can place any number of
  3762. values  in  DATA statements  --  which may stretch over several lines  --
  3763. without worrying about counting the number of values entered.
  3764.   Another  variation of the READ statement involves assigning information
  3765. from the same DATA line to different variables. This information can even
  3766. be  a  mixture of string data and numeric values.  You can do all this in
  3767. the following program that will READ a name,  some scores --  say bowling
  3768. -- and print the name, scores, and the average score:
  3769.  
  3770.   NEW
  3771.  
  3772.   10 READ N$, A, B, C
  3773.   20 PRINT N$;"'S SCORES WERE :"; A ;" "; B ;" "; C
  3774.   30 PRINT "AND THE AVERAGE IS :";(A+B+C)/3
  3775.   40 PRINT : GOTO 10
  3776.   50 DATA MIKE, 190, 185, 165, DICK, 225, 245, 190
  3777.   60 DATA JOHN, 155, 185, 205, PAUL, 160, 179, 187
  3778.  
  3779.   RUN
  3780.   MIKE'S SCORES WERE : 190   185   165
  3781.   AND THE AVERAGE IS : 180
  3782.  
  3783.   DICK'S SCORES WERE : 225   245   190
  3784.   AND THE AVERAGE IS : 220
  3785.  
  3786.   In  running  the  program,  the DATA statements were set up in the same
  3787. order  that  READ statement expected the information:  a name (a string),
  3788. then three values. In other words N$ the first time through gets the data
  3789. "MIKE",  A  in the READ corresponds to 190 in the DATA statement,  "B" to
  3790. 185  and  "C" to 165.  The process is then repeated in that order for the
  3791. remainder of the information.  (DICK and his scores, JOHN and his scores,
  3792. and PAUL and his scores.)
  3793.  
  3794.  
  3795. 8.3. Subscribed Variables
  3796.  
  3797.   In the past we've used only simple BASIC variables,  such as A, A$, and
  3798. NU to present values.  These were a single letter followed by a letter or
  3799. single digit. In any of the programs that you would write, it is doubtful
  3800. that  we would have a need for more variable names than possible with all
  3801. the combinations of letters or numbers available.  But you are limited in
  3802. the way variables are used with programs.
  3803.   Now let's introduce the concept of subscripted variables.
  3804.  
  3805.                                A(1)
  3806.                                ^ ^
  3807.                                | |___ Subscript
  3808.                                |_____ Variable
  3809.  
  3810.   This would be said: A sub 1. A subscribed variable consists of a letter
  3811. followed  by  a  subscript  enclosed within parentheses.  Please note the
  3812. difference  between  A,  A1,  and  A(1).  Each is unique.  Only A(1) is a
  3813. subscripted variable.
  3814.   Subscripted  variables,  like simple variables,  name a memory location
  3815. within  the  computer.  Think  of subscripted variables as boxes to store
  3816. information, just like simple variables:
  3817.  
  3818.         +------------------------+
  3819.   A(0)  |                        |
  3820.         +------------------------+
  3821.   A(1)  |                        |
  3822.         +------------------------+
  3823.   A(2)  |                        |
  3824.         +------------------------+
  3825.   A(3)  |                        |
  3826.         +------------------------+
  3827.   A(4)  |                        |
  3828.         +------------------------+
  3829.  
  3830. If you wrote:
  3831.  
  3832.   10 A(0) = 25 : A(3) = 55 : A(4) = -45.3
  3833.  
  3834.   Then memory would look like this:
  3835.  
  3836.         +------------------------+
  3837.   A(0)  | 25                     |
  3838.         +------------------------+
  3839.   A(1)  |                        |
  3840.         +------------------------+
  3841.   A(2)  |                        |
  3842.         +------------------------+
  3843.   A(3)  | 55                     |
  3844.         +------------------------+
  3845.   A(4)  | -45.3                  |
  3846.         +------------------------+
  3847.  
  3848.   This  group  of subscripted variables is also called an array.  In this
  3849. case, a one-dimensional array. Later on, we'll introduce multidimensional
  3850. arrays.
  3851.   Subscripts  can  also  be  more  complex to include other variables, or
  3852. computations. The following are valid subscripted variables:
  3853.  
  3854.   A(X)  A(X+1)  A(2+1)  A(1*3)
  3855.  
  3856.   The  expressions  within the parentheses are evaluated according to the
  3857. same rules for arithmetic operations in Chapter 2.
  3858.   Now  that the ground rules are in place,  how can subscripted variables
  3859. be  put to use?  One way is to store a list of numbers entered with INPUT
  3860. or READ statements.
  3861.   Let's use subscripted variables to do the averages a different way.
  3862.  
  3863.    5 PRINT CHR$(147)
  3864.   10 INPUT "HOW MANY NUMBERS :"; X
  3865.   20 FOR A = 1 TO X
  3866.   30 PRINT "ENTER VALUE #"; A ;: INPUT B(A)
  3867.   40 NEXT
  3868.   50 SU = 0
  3869.   60 FOR A = 1 TO X
  3870.   70 SU = SU + B(A)
  3871.   80 NEXT
  3872.   90 PRINT : PRINT "AVERAGE ="; SU/X
  3873.  
  3874.   RUN
  3875.   HOW MANY NUMBERS :? 5
  3876.   ENTER VALUE # 1 ? 125
  3877.   ENTER VALUE # 2 ? 167
  3878.   ENTER VALUE # 3 ? 189
  3879.   ENTER VALUE # 4 ? 167
  3880.   ENTER VALUE # 5 ? 158
  3881.  
  3882.   AVERAGE = 161.2
  3883.  
  3884.   There  might  have been an easier way to accomplish what we did in this
  3885. program, but it illustrates how subscripted variables work.  Line 10 asks
  3886. for  how  many  numbers will be entered.  This variable,  X,  acts as the
  3887. counter for the loop within  which values are entered and assigned to the
  3888. subscripted variable, B.
  3889.   Each time through the INPUT loop,  A is increased by 1  and so the next
  3890. value  entered  is  assigned  to  the  next  element in the array A.  For
  3891. example,  the  first  time  through  the  loop A = 1,  so the first value
  3892. entered is assigned to B(1). The next time through, A = 2; the next value
  3893. is assigned to B(2), and so on until all the values have been entered.
  3894.   But now a big difference comes into play. Once all the values have been
  3895. entered,  they  are  stored  in  the array,  ready to be put to work in a
  3896. variety of ways.  Before,  you kept a running total each time through the
  3897. INPUT  or  READ  loop,  but never could get back the individual pieces of
  3898. data without re-reading the information.
  3899.   In  line  50  through 80,  another loop has been designed to add up the
  3900. various elements of the array and then display the average. This separate
  3901. part  of  the  program shows that all of the values are stored and can be
  3902. accessed as needed.
  3903.   To  prove  that  all  of  the  individual  values  are  actually stored
  3904. separately in an array,  type the following immediately after running the
  3905. previous program:
  3906.  
  3907.   FOR A=1 TO 5 : ? B(A), : NEXT
  3908.   125        167        189        167
  3909.   158
  3910.  
  3911.   The  display  will show your actual values as the contents of the array
  3912. are PRINTed.
  3913.  
  3914.  
  3915. 8.4. Dimension
  3916.  
  3917.   If you tried to enter more than 10 numbers in the previous example, you
  3918. got a BAD SUBSCRIPT ERROR.  Arrays of up to eleven elements (subscripts 0
  3919. to 10 for a one-dimensional array) may used where needed,  just as simple
  3920. variables  can  be  used  anywhere within a program.  Arrays of more than
  3921. eleven elements need to be "declared" in the dimension statement.
  3922.   Add this line to the program:
  3923.  
  3924.   5 DIM B(100)
  3925.  
  3926.   This  lets  the  computer  know  that  you  will  have a maximum of 100
  3927. elements in the array.
  3928.   The  dimension  statement may  also  be  used  with a variable,  so the
  3929. following line could replace line 5 (don't forget to eliminate line 5):
  3930.  
  3931.   15 DIM B(X)
  3932.  
  3933.   This  would  dimension  the  array with the exact number of values that
  3934. will be entered.
  3935.   Be careful, though.  Once dimensioned, an array cannot be redimensioned
  3936. in another part of the program.  You can,  however,  have multiple arrays
  3937. within the program and dimension them all on the same line, like this:
  3938.  
  3939.   10 DIM C(20), D(50), E(40)
  3940.  
  3941.  
  3942. 8.5. Simulated Dice Roll With Arrays
  3943.  
  3944.   As  programs become more complex,  using subscripted variables will cut
  3945. down on the number of statements needed,  and make the program simpler to
  3946. write.
  3947.   A single subscribed variable can be used, for example, to keep track of
  3948. the number of times a particular face turns up:
  3949.  
  3950.   10 INPUT "HOW MANY ROLLS: "; X
  3951.   20 FOR L = 1 TO X
  3952.   30 R = INT(6*RND(1))+1
  3953.   40 F(R) = F(R) + 1
  3954.   50 NEXT L
  3955.   60 PRINT "FACE", "NUMBER OF TIMES"
  3956.   70 FOR C=1 TO 6 : PRINT C, F(C) : NEXT
  3957.  
  3958.   The array F,  for FACE,  will be used to keep track of how many times a
  3959. particular face turns up.  For example, every time a 2 is thrown, F(2) is
  3960. increased  by  one.  By  using  the same element of the array to hold the
  3961. actual  number on the face that is thrown,  we've eliminated the need for
  3962. five other variables (one for each face) and numerous statements to check
  3963. and see what number is thrown.
  3964.   Line 10 asks for how many rolls you want to simulate.
  3965.   Line 20 establishes the loop  to perform the random roll  and increment
  3966. the proper element of the array by one for each toss.
  3967.   After  all  of  the  required tosses are completed,  line 60 PRINTs the
  3968. heading and line 70 PRINTs the number of times each face shows up.
  3969.   A sample run might look like this:
  3970.  
  3971.   HOW MANY ROLLS: ? 1000
  3972.   FACE       NUMBER OF TIMES
  3973.    1          148
  3974.    2          176
  3975.    3          178
  3976.    4          166
  3977.    5          163
  3978.    6          169
  3979.  
  3980.   Well, at least it wasn't loaded!
  3981.   Just  as a comparison,  the following is one way of re-writing the same
  3982. program, but without using subscripted variables. Don't bother to type it
  3983. in, but do notice the additional statements necessary.
  3984.  
  3985.   10 INPUT "HOW MANY ROLLS: "; X
  3986.   20 FOR L = 1 TO X
  3987.   30 R = INT(6*RND(1))+1
  3988.   40 IF R = 1 THEN F1 = F1 + 1 : NEXT
  3989.   41 IF R = 2 THEN F2 = F2 + 1 : NEXT
  3990.   42 IF R = 3 THEN F3 = F3 + 1 : NEXT
  3991.   43 IF R = 4 THEN F4 = F4 + 1 : NEXT
  3992.   44 IF R = 5 THEN F5 = F5 + 1 : NEXT
  3993.   45 IF R = 6 THEN F6 = F6 + 1 : NEXT
  3994.   60 PRINT "FACE", "NUMBER OF TIMES"
  3995.   70 PRINT 1, F1
  3996.   71 PRINT 2, F2
  3997.   72 PRINT 3, F3
  3998.   73 PRINT 4, F4
  3999.   74 PRINT 5, F5
  4000.   75 PRINT 6, F6
  4001.  
  4002.   The program has doubled in size from 7 to 16 lines.  In larger programs
  4003. the  space  savings  from  using  subscripted variables will be even more
  4004. dramatic.
  4005.  
  4006.  
  4007. 8.6. Two-Dimensional Arrays
  4008.  
  4009.   Earlier  in  this chapter you experimented with one-dimensional arrays.
  4010. This  type of array was visualized as a group of consecutive boxes within
  4011. memory each holding an element of the array. What would you expect a two-
  4012. dimensional array to look like?
  4013.   First, a two-dimensional array would be written like this:
  4014.  
  4015.                               A(4,6)
  4016.                               ^ ^ ^
  4017.                               | | |
  4018.                               | Subscripts
  4019.                               |
  4020.                           Array Name
  4021.  
  4022. and could be represented as a two-dimensional grid within memory:
  4023.  
  4024.              0       1       2       3       4       5       6
  4025.          +-------+-------+-------+-------+-------+-------+-------+
  4026.     0    |       |       |       |       |       |       |       |
  4027.          +-------+-------+-------+-------+-------+-------+-------+
  4028.     1    |       |       |       |       |       |       |       |
  4029.          +-------+-------+-------+-------+-------+-------+-------+
  4030.     2    |       |       |       |       |       |       |       |
  4031.          +-------+-------+-------+-------+-------+-------+-------+
  4032.     3    |       |       |       |       |       |       |       |
  4033.          +-------+-------+-------+-------+-------+-------+-------+
  4034.     4    |       |       |       |       |       |       |       |
  4035.          +-------+-------+-------+-------+-------+-------+-------+
  4036.  
  4037.   The  subscripts  could be thought of as representing the row and column
  4038. within the table where the particular element of the array is stored.
  4039.  
  4040.                               A(3,4) = 255
  4041.                               ^   ^
  4042.                               |   |___ Column
  4043.                               |
  4044.                              Row
  4045.  
  4046.              0       1       2       3       4       5       6
  4047.          +-------+-------+-------+-------+-------+-------+-------+
  4048.     0    |       |       |       |       |       |       |       |
  4049.          +-------+-------+-------+-------+-------+-------+-------+
  4050.     1    |       |       |       |       |       |       |       |
  4051.          +-------+-------+-------+-------+-------+-------+-------+
  4052.     2    |       |       |       |       |       |       |       |
  4053.          +-------+-------+-------+-------+-------+-------+-------+
  4054.     3    |       |       |       |       |  255  |       |       |
  4055.          +-------+-------+-------+-------+-------+-------+-------+
  4056.     4    |       |       |       |       |       |       |       |
  4057.          +-------+-------+-------+-------+-------+-------+-------+
  4058.  
  4059.   If we assigned the value 255 to A(3,4), then 255 could be thought of as
  4060. being placed in the 4th column of the 3rd row within the table.
  4061.   Two-dimensional  arrays  behave  according  to the same rules that were
  4062. established for one-dimensional arrays:
  4063.  
  4064.   They must be dimensioned:                   DIM A(20,20)
  4065.   Assignment of data:                         A(1,1) = 255
  4066.   Assign values to other variables:           AB = A(1,1)
  4067.   PRINT values:                               PRINT A(1,1)
  4068.  
  4069.   If  two-dimensional  arrays work like their smaller counterparts,  what
  4070. additional capabilities will the expanded arrays handle?
  4071.   Try  this:  can  you  think  of  a way using a two-dimensional array to
  4072. tabulate  the results of a questionnaire for your club that involved four
  4073. questions  and  had up to three responses for each question?  The problem
  4074. could be represented like this:
  4075.  
  4076.                            CLUB QUESTIONNAIRE
  4077.  
  4078. Q1: ARE YOU IN FAVOR OF RESOLUTION #1?
  4079.  
  4080.      _1-YES  _2-NO  _3-UNDECIDED
  4081.  
  4082.                     ... and so on.
  4083.  
  4084.   The array table for this problem could be represented like this:
  4085.  
  4086.                                          RESPONSES
  4087.  
  4088.                           YES               NO           UNDECIDED
  4089.  
  4090.                    +----------------+----------------+----------------+
  4091.   QUESTION 1       |                |                |                |
  4092.                    +----------------+----------------+----------------+
  4093.   QUESTION 2       |                |                |                |
  4094.                    +----------------+----------------+----------------+
  4095.   QUESTION 3       |                |                |                |
  4096.                    +----------------+----------------+----------------+
  4097.   QUESTION 4       |                |                |                |
  4098.                    +----------------+----------------+----------------+
  4099.  
  4100.   The  program  to  do  the actual tabulation for the questionnaire might
  4101. look like that:
  4102.  
  4103.    20 PRINT "{CLR/HOME}"
  4104.    30 FOR R = 1 TO 4
  4105.    40 PRINT "QUESTION # :"; R
  4106.    50 PRINT "1-YES  2-NO  3-UNDECIDED"
  4107.    60 PRINT "WHAT WAS THE RESPONSE : ";
  4108.    61 GET C : IF C<1 OR C>3 THEN 61
  4109.    65 PRINT C: PRINT
  4110.    70 A(R,C) = A(R,C) + 1 : REM UPDATE ELEMENT
  4111.    80 NEXT R
  4112.    85 PRINT
  4113.    90 PRINT "DO YOU WANT TO ENTER ANOTHER" : PRINT "RESPONSE (Y/N) ?";
  4114.   100 GET A$ : IF A$ = "" THEN 100
  4115.   110 IF A$ = "Y" THEN 20
  4116.   120 IF A$ <> "N" THEN 100
  4117.   130 PRINT "{CLR/HOME}" ; "THE TOTAL RESPONSES WERE:" : PRINT
  4118.   140 PRINT SPC(18); "RESPONSE"
  4119.   141 PRINT "QUESTION", "YES", "NO", "UNDECIDED"
  4120.   142 PRINT "--------   -----------------------------"
  4121.   150 FOR R = 1 TO 4
  4122.   160 PRINT R, A(R,1), A(R,2), A(R,3)
  4123.   170 NEXT R
  4124.  
  4125.   RUN
  4126.  
  4127.   QUESTION # : 1
  4128.   1-YES  2-NO  3-UNDECIDED
  4129.   WHAT WAS THE RESPONSE : 1
  4130.  
  4131.   DO YOU WANT TO ENTER ANOTHER
  4132.   RESPONSE (Y/N) ?
  4133.  
  4134.   QUESTION # : 2
  4135.   1-YES  2-NO  3-UNDECIDED
  4136.   WHAT WAS THE RESPONSE : 1
  4137.  
  4138.   And so on...
  4139.  
  4140.   THE TOTAL RESPONSES WERE:
  4141.  
  4142.                     RESPONSE
  4143.   QUESTION   YES       NO        UNDECIDED
  4144.   --------   -----------------------------
  4145.    1          6         1         0
  4146.    2          5         2         0
  4147.    3          7         0         0
  4148.    4          2         4         1
  4149.  
  4150.   This  program makes use of many of the programming techniques that have
  4151. been  presented  so far.  Even  if you don't have any need for the actual
  4152. program right now, see if you can follow how the program works.
  4153.   The  heart  of this program is a 4 by 3 two-dimensional array,  A(4,3).
  4154. The total responses for each possible answer to each question are held in
  4155. the  appropriate  element  of the array.  For the sake of simplicity,  we
  4156. don't use the first rows and column (A(0,0) to A(0,4)). Remember, though,
  4157. that those elements are always present in any array you design.
  4158.   In  practice,   if  question  one  is  answered  YES,  then  A(1,1)  is
  4159. incremented  by  one  --  row  1  for  question  1 and column 1 for a YES
  4160. response.  The rest of the questions and answers follow the same pattern.
  4161. A  NO response for question three would add one to element A(3,2), and so
  4162. on.
  4163.  
  4164.  
  4165.  
  4166. APPENDICES
  4167.  
  4168. INTRODUCTION
  4169.  
  4170.   Now that you've become more intimately involved with your Commodore 64,
  4171. we want you to know that our customer support does not stop here. You may
  4172. not know it, but Commodore has been in business for over 23 years. In the
  4173. 1970's  we  introduced  the  first  self-contained personal computer (the
  4174. PET). We have since become the leading computer company in many countries
  4175. of  the  world.  Our  ability  to design and manufacture our own computer
  4176. chips  allows us to bring you new and better personal computers at prices
  4177. way below what you'd expect for this level of technical excellence.
  4178.   Commodore  is committed to supporting not only you,  the end user,  but
  4179. also  the  dealer you bought your computer from,  magazines which publish
  4180. how-to  articles  showing  you  new applications or techniques,  and  ...
  4181. importantly  ...  software  developers who produce programs on cartridge,
  4182. disk  ond tape for use with your computer.  We encourage you to establish
  4183. or  join  a  Commodore  "user  club"  where you can learn new techniques,
  4184. exchange  ideas and share discoveries.  We publish two separate magazines
  4185. which contain programming tips, information on new products and ideas for
  4186. computer applications. (See Appendix N).
  4187.   In North America,  Commodore provides a "Commodore Information Network"
  4188. on the CompuServe Information Service ... to access this network, all you
  4189. need  is  your  Commodore 64 computer and our low cost VICMODEM telephone
  4190. interface cartridge (or other compatible modem).
  4191.   The following APPENDICES contain charts,  tables, and other information
  4192. which  help  you  program  your Commodore 64 faster and more efficiently.
  4193. They  also include important information on the wide variety of Commodore
  4194. products you may be interested in,  and a bibliography listing of over 20
  4195. books  and  magazines  which can help you develop your programming skills
  4196. and  keep  you current on the latest information concerning your computer
  4197. and peripherals.
  4198.  
  4199.  
  4200. APPENDIX A
  4201.  
  4202. COMMODORE 64 ACCESSORIES AND SOFTWARE
  4203.  
  4204.  
  4205. ACCESSORIES
  4206.  
  4207.   The  Commodore  64  will  support  Commodore VIC 20 storage devices and
  4208. accessories  --  DATASSETTE  recorder,  disk  drive, modem, printer -- so
  4209. your system can expand to keep pace with changing needs.
  4210.  
  4211.   o Datassette  Recorder --  This low cost tape unit enables programs and
  4212.     data  to be stored on cassette tape, and played back at a later time.
  4213.     The datassette can also be used to play pre-written programs.
  4214.  
  4215.   o Disk  --   The  single  disk  unit  uses  standard  5.25-inch  floppy
  4216.     diskettes,  about the size of a 45 RPM record,  to store programs and
  4217.     data.  Disks  allow  faster  access  to  data  and hold up to 170,000
  4218.     characters of information each. Disk units are "intelligent", meaning
  4219.     they  have  their  own  microprocessor  and memory.  Disks require no
  4220.     resources from the Commodore 64, such as using part of main memory.
  4221.  
  4222.   o Modem -- A low-cost communication device,  the VICMODEM allows access
  4223.     to  other  computers  over ordinary telephone lines.  Users will have
  4224.     access  to the full resources of large data bases such as The Source,
  4225.     CompuServe,  and  Dow  Jones  News  Retrieval  Service (North America
  4226.     only).
  4227.  
  4228.   o Printer -- The VIC printer produces printed copies of programs, data,
  4229.     or  graphics.  This  30  character per second dot-matrix printer uses
  4230.     plain tractor feed paper and other inexpensive supplies.  The printer
  4231.     attaches   directly   to  the  Commodore 64  without  any  additional
  4232.     interfaces.
  4233.  
  4234.   o Interface Cartridges --  A number of specialized cartridges  will  be
  4235.     available for the Commodore 64 to allow various standard devices such
  4236.     as modems,  printers,  controllers, and instruments to be attached to
  4237.     the system.
  4238.  
  4239.   With  a  special IEEE-488 Cartridge,  the Commodore 64 will support the
  4240. full range of CBM peripherals including disk units and printers.
  4241.   Additionally,  a  Z80  cartridge  will  allow  you  to  run CP/M on the
  4242. Commodore  64,  giving  you  access  to the largest base of microcomputer
  4243. applications available.
  4244.  
  4245.  
  4246. SOFTWARE
  4247.  
  4248.   Several  categories  of  software will be offered for the Commodore 64,
  4249. providing  you  with  a  wide  variety  of  personal,  entertainment, and
  4250. educational applications to choose from.
  4251.  
  4252. Business Aids
  4253.  
  4254.   o An Electronic Spreadsheet package will allow you to plan budgets, and
  4255.     perform  "what if?" analysis.  And with the optional graphic program,
  4256.     meaningful graphs may be created from the spreadsheet data.
  4257.  
  4258.   o Financial planning, such as loan amortization, will be easily handled
  4259.     with the Financial Planning Package.
  4260.  
  4261.   o A number of Professional Time Management programs  will  help  manage
  4262.     appointments and work load.
  4263.  
  4264.   o Easy-to-use Data Base programs  will  allow  you  to  keep  track  of
  4265.     information ... mailing lists ... phone lists ... inventories ... and
  4266.     organize information in a useful form.
  4267.  
  4268.   o Professional Word Processing programs will turn the Commodore 64 into
  4269.     a full-featured word processor.  Typing and revising memos,  letters,
  4270.     and other text material become a breeze.
  4271.  
  4272. Entertainment
  4273.  
  4274.   o The highest quality games will be available on plug-in cartridges for
  4275.     the Commodore 64,  providing hours of enjoyment.  These programs make
  4276.     use  of  the  high  resolution graphics and full sound range possible
  4277.     with the Commodore 64.
  4278.  
  4279.   o Your  Commodore 64 allows you all the fun and excitement available on
  4280.     MAX  games  because  these  two  machines  have completely compatible
  4281.     cartridges.
  4282.  
  4283. Education
  4284.  
  4285.   o The  Commodore 64  is  a  tutor  that  never  tires  and always gives
  4286.     personal  attention.   Besides  access   to  much  of  the  vast  PET
  4287.     educational  programs,  additional educational languages that will be
  4288.     available  for  the  Commodore 64  include PILOT,  LOGO and other key
  4289.     advanced packages.
  4290.  
  4291.  
  4292.  
  4293. APPENDIX B
  4294.  
  4295. ADVANCED CASSETTE OPERATION
  4296.  
  4297.   Besides  saving  copies  of  your  programs  on  tape, the Commodore 64
  4298. can  also  store  the  values  of variables and other items of data, in a
  4299. group  called  a  FILE.  This  allows  you to store even more information
  4300. than could be held in the computer's main memory at one time.
  4301.   Statements  used  with  data  files are OPEN, CLOSE, PRINT#, INPUT# and
  4302. GET#. The system variable ST (status) is used to check for tape markers.
  4303.   In writing data to tape,  the same concepts are used as when displaying
  4304. information on the computer's screen. But instead of PRINTing information
  4305. on  the  screen,  the information is PRINTed on tape using a variation of
  4306. the PRINT command -- PRINT#.
  4307.   The following program illustrates how this works:
  4308.  
  4309.   10 PRINT "WRITE-TO-TAPE-PROGRAM"
  4310.   20 OPEN 1,1,1, "DATA FILE"
  4311.   30 PRINT "TYPE DATA TO BE STORED OR TYPE STOP"
  4312.   40 PRINT
  4313.   50 INPUT "DATA"; A$
  4314.   60 PRINT#1, A$
  4315.   70 IF A$ <> "STOP" THEN 40
  4316.   80 PRINT
  4317.   90 PRINT "CLOSING FILE"
  4318.  100 CLOSE 1
  4319.  
  4320.   The  first  thing  that  you  must do is OPEN a file (in this case DATA
  4321. FILE). Line 10 handles that.
  4322.   The program prompts for the data you want  to save on tape  in line 50.
  4323. Line 60 writes what you typed  -- held in A$  -- onto the tape.  And the
  4324. process continues.
  4325.   If you type STOP, line 100 CLOSEs the file.
  4326.   To retrieve the information, rewind the tape, and try this:
  4327.  
  4328.   10 PRINT "READ-TAPE-PROGRAM"
  4329.   20 OPEN 1,1,0, "DATA FILE"
  4330.   30 PRINT "FILE OPEN"
  4331.   40 PRINT
  4332.   50 INPUT#1, A$
  4333.   60 PRINT A$
  4334.   70 IF A$ <> "STOP" THEN 40
  4335.   80 PRINT
  4336.   90 PRINT "CLOSING FILE"
  4337.  100 CLOSE 1
  4338.  
  4339.   Again,  this  file  "DATA  FILE"  first  must be OPENed. In line 50 the
  4340. program  INPUTs  A$  from tape and also PRINTs A$ on the screen. Then the
  4341. whole  process  is  repeated  until  "STOP"  is  found,  which  ENDs  the
  4342. program.
  4343.   A  variation  of  GET-GET#  can also be used to read the data back from
  4344. tape. Replace lines 50-70 in the program above with:
  4345.  
  4346.   50 GET#1, A$
  4347.   60 IF A$ <> "" THEN 50
  4348.   70 PRINT A$, ASC(A$)
  4349.  
  4350.  
  4351.  
  4352. APPENDIX C
  4353.  
  4354. COMMODORE 64 BASIC
  4355.  
  4356.  
  4357.   This  manual  has  given  you  an introduction to the BASIC language --
  4358. enough  for  you  to  get a feel for computer programming and some of the
  4359. vocabulary  involved.  This  appendix  gives a complete list of the rules
  4360. (SYNTAX)   of  Commodore  64  BASIC,  along  with  concise  descriptions.
  4361. Please  experiment  with  these  commands.  Remember,  you  can't  do any
  4362. permanent  damage  to  the  computer  by just typing in programs, and the
  4363. best way to learn computing is by doing.
  4364.   This  appendix  is  divided  into  sections  according to the different
  4365. types of operations in BASIC. These include:
  4366.  
  4367. 1. Variables  and  Operators:  describes the different type of variables,
  4368.    legal variable names, and arithmetic and logical operators.
  4369. 2. Commands:  describes  the  commands used to work with programs,  edit,
  4370.    store and erase them.
  4371. 3. Statements:  describes  the  BASIC program statements used in numbered
  4372.    lines of programs.
  4373. 4. Functions: describes the string, numeric, and print functions.
  4374.  
  4375.  
  4376. VARIABLES
  4377.  
  4378.   The Commodore 64 uses three types of variables in BASIC. These are real
  4379. numeric, integer numeric, and string (alphanumeric) variables.
  4380.   Variable  names  may consist of a single letter, a letter followed by a
  4381. number, or two letters.
  4382.   An  integer  variable  is specified by using the percent (%) sign after
  4383. the  variable name.  String variable have the dollar sign ($) after their
  4384. name.
  4385.  
  4386. Examples
  4387.  
  4388.   Real Variable Names: A, A5, BZ
  4389.   Integer Variable Names: A%, A5%, BZ%
  4390.   String Variable Names: A$, A5$, BZ$
  4391.  
  4392.   Arrays are lists of variables with the same name,  using extra  numbers
  4393. to specify the element of the array.  Arrays are defined  using  the  DIM
  4394. statement, and may contain floating point, integer,  or string variables.
  4395. The array variable name is followed by a set of parentheses ( ) enclosing
  4396. the number of variables in the list.
  4397.  
  4398.   A(7), BZ%(11), A$(50), PT(20,20)
  4399.  
  4400.   NOTE:  There are three variable names which are reserved for use by the
  4401. Commodore 64, and may not be defined by you.  These variables are: ST, TI
  4402. and  TI$.   ST  is  a  status  variable  which  relates  to  input/output
  4403. operations.  The value of ST will change  if there is a problem loading a
  4404. program from disk or tape.
  4405.   TI and TI$ are variables which relate to the real-time clock built into
  4406. the Commodore 64. The variable TI is updated every 1/60th of a second. It
  4407. starts at 0 when the computer is turned on, and is reset only by changing
  4408. the value of TI$.
  4409.   TI$  is a string which is constantly updated by the system.  The  first
  4410. two characters contain the number of hours , the  3rd and 4th  characters
  4411. the number of minutes,  and  the 5th and 6th characters are the number of
  4412. seconds.  This  variable  can  be  given  any numeric value,  and will be
  4413. updated from that point.
  4414.  
  4415.   TI$ = "101530" sets the clock to 10:15 and 30 seconds AM.
  4416.  
  4417.   This clock is erased when the computer is turned  off,  and  starts  at
  4418. zero when the system is turned back on.
  4419.  
  4420.  
  4421. OPERATORS
  4422.  
  4423.   The arithmetic operators include the following signs:
  4424.  
  4425.   +  Addition
  4426.   -  Subtraction
  4427.   *  Multiplication
  4428.   /  Division
  4429.   ^  Raising to a power (exponentiation)
  4430.  
  4431.   On a line  containing  more than one operator,  there is a set order in
  4432. which operations always occur. If several operations are used together on
  4433. the  same  line,  the  computer  assigns  priorities  as follows:  First,
  4434. exponentiation. Next, multiplication and division, and last, addition and
  4435. subtraction.
  4436.   You can change the order of operations  by enclosing within parentheses
  4437. the calculation to be performed first. Operations enclosed in parentheses
  4438. will take place before other operations.
  4439.   There are also operations for equalities and inequalities:
  4440.  
  4441.   =  Equal To
  4442.   <  Less Than
  4443.   >  Greater Than
  4444.   <= Less Than or Equal To
  4445.   >= Greater Than or Equal To
  4446.   <> Not Equal To
  4447.  
  4448.   Finally, there are three logical operators:
  4449.  
  4450.   AND
  4451.   OR
  4452.   NOT
  4453.  
  4454.   These are used most  often  to  join  multiple  formulas  in  IF...THEN
  4455. statements. For example:
  4456.  
  4457.   IF A=B AND C=D THEN 100  (Requires both parts to be true)
  4458.   IF A=B OR  C=D THEN 100  (Allows either part to be true)
  4459.  
  4460.  
  4461. COMMANDS
  4462.  
  4463. CONT (Continue)
  4464.  
  4465.   This command is used to restart the execution of a  program  which  has
  4466. been stopped by either using the <STOP> key, a STOP statement,  or an END
  4467. statement within the program. The program will restart at the exact place
  4468. from where it left off.
  4469.   CONT will not work if you have changed or added lines  to  the  program
  4470. (or even just moved the cursor),  or if the  program  halted  due  to  an
  4471. error, or if you caused an error before trying to restart the program. In
  4472. these cases you will get a CAN'T CONTINUE ERROR.
  4473.  
  4474. LIST
  4475.  
  4476.   The  LIST  command  allows  you  to look at lines of a BASIC program in
  4477. memory.  You  can  ask  for  the  entire program to be displayed, or only
  4478. certain line numbers.
  4479.  
  4480.   LIST              Shows entire program
  4481.   LIST 10-          Shows only from line 10 until end
  4482.   LIST 10           Shows only line 10
  4483.   LIST -10          Shows lines from beginning until 10
  4484.   LIST 10-20        Shows line from 10 to 20, inclusive
  4485.  
  4486. LOAD
  4487.  
  4488.   This  command  is  used  to  transfer  a program from tape or disk into
  4489. memory  so  the  program  can  be  used.  If  you  just type LOAD and hit
  4490. RETURN,  the  first  program found on the cassette unit will be placed in
  4491. memory.  The  command  may  be followed by a program name enclosed within
  4492. quotes.  The  name  may  then  be  followed  by  a  comma and a number or
  4493. numeric  variable,  which  acts  as a device number to indicate where the
  4494. program is coming from.
  4495.  
  4496.   If  no  device  number  is  given,  the Commodore 64 assumes device #1,
  4497. which  is  the  cassette  unit.  The  other device commonly used with the
  4498. LOAD command is the disk device, which is device #8.
  4499.  
  4500.   LOAD              Reads in the next program on tape
  4501.   LOAD "HELLO"      Searches tape for program called HELLO,
  4502.                     and loads program, if found
  4503.   LOAD A$           Looks for program whose name is in the variable A$
  4504.   LOAD "HELLO",8    Looks for program called HELLO on the disk drive
  4505.   LOAD "*",8        Looks for first program on disk
  4506.  
  4507. NEW
  4508.  
  4509.   This  command  erases  the  entire  program in memory,  and also clears
  4510. out  any  variables  that  may  have  been  used.  Unless the program was
  4511. SAVEd, it is lost. BE CAREFUL WHEN YOU USE THIS COMMAND.
  4512.   The NEW command can also be used as a BASIC program statement. When the
  4513. program reaches this line,  the program is erased.  This is useful if you
  4514. want to leave everything neat when the program is done.
  4515.  
  4516. RUN
  4517.  
  4518.   This  command  causes  execution  of  a  program,  once  the program is
  4519. loaded  into  memory.  If  there  is  no  line  number following RUN, the
  4520. computer  will  start  with  the  lowest line number. If a line number is
  4521. designated, the program will start executing from the specified line.
  4522.  
  4523.   RUN               Starts program at lowest line number
  4524.   RUN 100           Starts execution at line 100
  4525.   RUN X             UNDEFINED STATEMENT ERROR. You must always specify an
  4526.                     actual line number, not a variable representation
  4527.  
  4528. SAVE
  4529.  
  4530.   This  command  will  store  the program currently in memory on cassette
  4531. or  disk.  If  you  just  type SAVE and RETURN, the program will be SAVEd
  4532. on  cassette.  The  computer  has no way of knowing if there is a program
  4533. already  on  that  tape, so be careful with your tapes or you may erase a
  4534. valuable program.
  4535.   If you type SAVE followed by a name in quotes or a string variable, the
  4536. computer  will  give  the  program  that  name,  so it can be more easily
  4537. located  and retrieved in the future.  The name may also be followed by a
  4538. device number.
  4539.   After  the  device  number,  there  can be a comma and a second number,
  4540. either  0  or  1. If the second number is 1, the Commodore 64 will put an
  4541. END-OF-TAPE  marker  after  your  program.  This signals the computer not
  4542. to  look  any  further on the tape if you were to give an additional LOAD
  4543. command.  If  you  try  to  LOAD  a program and the computer finds one of
  4544. these markers, you will get a FILE NOT FOUND ERROR.
  4545.  
  4546.   SAVE              Stores program to tape without name
  4547.   SAVE "HELLO"      Stores on tape with name HELLO
  4548.   SAVE A$           Stores on tape with name A$
  4549.   SAVE "HELLO",8    Stores on disk with name HELLO
  4550.   SAVE "HELLO",1,1  Stores on tape with name HELLO and follows
  4551.                     program with END-OF-TAPE marker
  4552.  
  4553. VERIFY
  4554.  
  4555.   This  command  causes  the  computer  to  check  the program on disk or
  4556. tape  against  the  one  in  memory.  This  is  proof that the program is
  4557. actually SAVEd,  in case the tape or disk is bad, or something went wrong
  4558. during  the  SAVE.  VERIFY  without anything after the command causes the
  4559. Commodore  64  to  check  the  next  program on tape, regardless of name,
  4560. against the program in memory.
  4561.   VERIFY  followed by a program name,  or a string variable,  will search
  4562. for that program and then check. Device numbers can also be included with
  4563. the verify command.
  4564.  
  4565.   VERIFY            Checks the next program on tape
  4566.   VERIFY "HELLO"    Searches for HELLO, checks against memory
  4567.   VERIFY "HELLO",8  Searches for HELLO on disk, then checks
  4568.  
  4569.  
  4570.  
  4571. STATEMENTS
  4572.  
  4573. CLOSE
  4574.  
  4575.   This  command  completes  and closes any files used by OPEN statements.
  4576. The number following CLOSE is the file number to be closed.
  4577.  
  4578.   CLOSE 2           Only file #2 is closed
  4579.  
  4580. CLR
  4581.  
  4582.   This command will erase any variables in memory, but leaves the program
  4583. itself intact.  This command is automatically executed when a RUN command
  4584. is given.
  4585.  
  4586. CMD
  4587.  
  4588.   CMD sends the output which normally would go to the screen (i.e., PRINT
  4589. statements,  LISTs,  but  not  POKEs  onto the screen)  to another device
  4590. instead.  This could be a printer,  or a data file on tape or disk.  This
  4591. device or file must be OPENed first.  The CMD command must be followed by
  4592. a number or numeric variable referring to the file.
  4593.  
  4594.   OPEN 1,4          OPENs device #4, which is the printer
  4595.   CMD 1             All normal output now goes to printer
  4596.   LIST              The program listing now goes to
  4597.                     the printer, not the screen
  4598.  
  4599.   To send output back to the screen, CLOSE the file with CLOSE 1.
  4600.  
  4601. DATA
  4602.  
  4603.   This  statement  is  followed  by  a  list  of items to be used by READ
  4604. statements.  Items  may  be numeric values or text strings, and items are
  4605. separated  by commas.  String items need not be inside quote marks unless
  4606. they contain space,  colon, or comma.  If two commas have nothing between
  4607. them, the value will be READ as a zero for a number, or an empty string.
  4608.  
  4609.   DATA 12, 14.5, "HELLO, MOM", 3.14, PART1
  4610.  
  4611. DEF FN
  4612.  
  4613.   This  command  allows you to define a complex calculation as a function
  4614. with a short name.  In the case of a long formula that is used many times
  4615. within the program, this can save time and space.
  4616.   This  function  name  will  be  FN and any legal variable name  (1 or 2
  4617. characters long).  First you must define the function using the statement
  4618. DEF  followed  by  the  function  name.  Following  the  name is a set of
  4619. parentheses enclosing a numeric variable. Then follows the actual formula
  4620. that  you want to define,  with the variable in the proper spot.  You can
  4621. then "call" the formula, substituting any number for the variable.
  4622.  
  4623.   10 DEF FN A(X) = 12 * ( 34.75 - X / .3 )
  4624.   20 PRINT FN A(7)                ^
  4625.                 ^                 |
  4626.                 |                 | 7 is inserted where
  4627.                 +-----------------+ X is in the formula
  4628.  
  4629. DIM
  4630.  
  4631.   When you use more than 11 elements of an array,  you must execute a DIM
  4632. statement for the array.  Keep in mind that the whole array takes up room
  4633. in  memory,  so  don't  create  an  array  much  larger than you'll need.
  4634. To  figure  the number of variables created with DIM,  multiply the total
  4635. number of elements in each dimension of the array.
  4636.  
  4637.   10 DIM A$(40), B7(15), CC%(4,4,4)
  4638.              ^       ^         ^
  4639.              |       |         |
  4640.    41 elements  16 elements  125 elements
  4641.  
  4642.   You  can  dimension more than one array in a DIM statement. However, be
  4643. careful not to dimension an array more than once.
  4644.  
  4645. END
  4646.  
  4647.   When a program encounters an END statement, the program halts, as if it
  4648. ran out of lines. You may use CONT to restart the program.
  4649.  
  4650. FOR ... TO ... STEP
  4651.  
  4652.   This statement works with the NEXT statement to repeat a section of the
  4653. program a set number of times. The format is:
  4654.  
  4655.   FOR (Var. Name)=(Start of Count) TO (End of Count) STEP (Count By)
  4656.  
  4657.   The  loop  variable  will  be  added  to  or subtracted from during the
  4658. program.  Without any STEP specified,  STEP is assumed to be 1. The start
  4659. count and end count are the limits to the value of the loop variable.
  4660.  
  4661.   10 FOR L = 1 to 10 STEP .1
  4662.   20 PRINT L
  4663.   30 NEXT L
  4664.  
  4665.   The end of the loop value may be followed by the word STEP  and another
  4666. number or variable.  In this case, the value following STEP is added each
  4667. time instead of 1. This allows you to count backwards, or by fractions.
  4668.  
  4669. GET
  4670.  
  4671.   The  GET  statement  allows  you  to  get  data from the keyboard,  one
  4672. character at a time. When GET is executed, the character that is typed is
  4673. assigned to the variable.  If no character is typed,  then a null (empty)
  4674. character is assigned.
  4675.   GET  is  followed by a variable name,  usually a string variable.  If a
  4676. numeric  variable  was  used and a nonnumeric key depressed,  the program
  4677. would halt with an error message.  The GET statement may be placed into a
  4678. loop,  checking for  any result.  This loop will continue  until a key is
  4679. hit.
  4680.  
  4681.   10 GET A$: IF  A$ = ""  THEN 10
  4682.  
  4683. GET#
  4684.  
  4685.   The GET# statement is used with a previously OPENed device or file,  to
  4686. input one character at a time from that device or file.
  4687.  
  4688.   GET #1,A$
  4689.  
  4690. This would input one character from a data file.
  4691.  
  4692. GOSUB
  4693.  
  4694.   This statement is similar to GOTO,  except the computer remembers which
  4695. program line it last executed before the GOSUB. When a line with a RETURN
  4696. statement  is  encountered,  the  program  jumps  back  to  the statement
  4697. immediately following the GOSUB.  This is useful if there is a routine in
  4698. your program that occurs in several parts of the program.
  4699. Instead of typing the routine over and over, execute GOSUBs each time the
  4700. routine is needed.
  4701.  
  4702.   20 GOSUB 800
  4703.  
  4704. GOTO or GO TO
  4705.  
  4706.   When a statement with the GOTO command is reached,  the next line to be
  4707. executed will be the one with the line number following the word GOTO.
  4708.  
  4709. IF ... THEN
  4710.  
  4711.   IF ... THEN lets the computer analyze a situation and take two possible
  4712. courses of action,  depending on the outcome.  If the expression is true,
  4713. the  statement  following  THEN  is  executed.  This  may  be  any  BASIC
  4714. statement.
  4715.   If the expression is false, the program goes directly to the next line.
  4716.   The expression being evaluated may be a variable or formula,  in  which
  4717. case it is considered true if nonzero,  and false if zero.  In most cases,
  4718. there  is an expression involving relational operators  (=, <, >, <=, >=,
  4719. <>, AND, OR, NOT).
  4720.  
  4721.   10 IF X > 10 THEN END
  4722.  
  4723. INPUT
  4724.  
  4725.   The  INPUT  statement  allows  the  program  to get data from the user,
  4726. assigning  that  data  to  a  variable.  The  program  will stop, print a
  4727. question  mark  (?)  on  the screen, and wait for the user to type in the
  4728. answer and hit RETURN.
  4729.   INPUT  is  followed  by  a  variable name, or a list of variable names,
  4730. separated by commas.  A message may be placed within quote marks,  before
  4731. the  list of variable names to be INPUT.  If more than one variable is to
  4732. be INPUT, they must be separated by commas when typed.
  4733.  
  4734.   10 INPUT "PLEASE ENTER YOUR FIRST NAME";A$
  4735.   20 PRINT "ENTER YOUR CODE NUMBER";: INPUT B
  4736.  
  4737. INPUT#
  4738.  
  4739.   INPUT#  is  similar  to INPUT,  but takes data from a previously OPENed
  4740. file or device.
  4741.  
  4742.   10 INPUT#1, A
  4743.  
  4744. LET
  4745.  
  4746.   LET  is  hardly  ever  used  in programs, since it is optional, but the
  4747. statement is the heart of all BASIC programs.  The variable name which is
  4748. to  be  assigned  the  result of a calculation is on the left side of the
  4749. equal sign, and the formula in the right.
  4750.  
  4751.   10 LET A = 5
  4752.   20 LET D$ = "HELLO"
  4753.  
  4754. NEXT
  4755.  
  4756.   NEXT  is  always  used in conjunction with the FOR statement.  When the
  4757. program  reaches a NEXT statement,  it checks the FOR statement to see if
  4758. the limit of the loop has been reached.  If the loop is not finished, the
  4759. loop  variable  is increased by the specified STEP value.  If the loop is
  4760. finished,  execution  proceeds  with  the  statement following NEXT.
  4761.   NEXT  may  be  followed by a variable name,  or list of variable names,
  4762. separated by commas.  If there are no names listed, the last loop started
  4763. is the one being completed. If variables are given, they are completed in
  4764. order from left to right.
  4765.  
  4766.   10 FOR X = 1 TO 100: NEXT
  4767.  
  4768. ON
  4769.  
  4770.   This command turns the GOTO and GOSUB commands into special versions of
  4771. the IF statement. ON is followed by a formula, which is evaluated. If the
  4772. result of the calculation is one, the first line on the list is executed;
  4773. if the result is 2, the second line is executed, and so on. If the result
  4774. is 0,  negative,  or  larger  than  the  list  of numbers,  the next line
  4775. executed will be the statement following the ON statement.
  4776.  
  4777.   10 INPUT X
  4778.   20 ON X GOTO 10,20,30,40,50
  4779.  
  4780. OPEN
  4781.  
  4782.   Then  OPEN  statement allows the Commodore 64 to access devices such as
  4783. the cassette recorder and disk for data,  a printer,  or even the screen.
  4784. OPEN  is followed by a number (0-255),  to which all following statements
  4785. will  refer.  There is usually a second number after the first,  which is
  4786. the device number.
  4787.   The device numbers are:
  4788.  
  4789.   0   Screen
  4790.   1   Cassette
  4791.   4   Printer
  4792.   8   Disk
  4793.  
  4794.   Following the device number may be a third number, separated again by a
  4795. third number, separated again by a comma, which is the secondary address.
  4796. In the case of the cassette,  this is 0 for read,  1 for write, and 2 for
  4797. write with end-of-tape marker.
  4798.   In the case of the disk,  the number refers to the buffer,  or channel,
  4799. number.  In  the  printer,  the  secondary address controls features like
  4800. expanded printing. See the Commodore 64 Programmer's Reference Manual for
  4801. more details.
  4802.  
  4803.   10 OPEN 1,0           OPENs the SCREEN as a device
  4804.   20 OPEN 2,1,0,"D"     OPENs the cassette for reading,
  4805.                         file to be searched for is D
  4806.   30 OPEN 3,4           OPENs the printer
  4807.   40 OPEN 4,8,15        OPENs the data channel on the disk
  4808.  
  4809.   Also see: CLOSE, CMD, GET#, INPUT#, and PRINT#, system variable ST, and
  4810. Appendix B.
  4811.  
  4812. POKE
  4813.  
  4814.   POKE is always followed by two numbers, or formulas. The first location
  4815. is a memory location; the second number is a decimal value from 0 to 255,
  4816. which  will  be  placed in the memory location,  replacing any previously
  4817. stored value.
  4818.  
  4819.   10 POKE 53281,0
  4820.   20 S = 4096 * 13
  4821.   30 POKE S + 29, 8
  4822.  
  4823. PRINT
  4824.  
  4825.   The  PRINT  statement  is  the  first one most people learn to use, but
  4826. there  are  a  number of variations to be aware of. PRINT can be followed
  4827. by:
  4828.  
  4829.   Text String with quotes
  4830.   Variable names
  4831.   Functions
  4832.   Punctuation marks
  4833.  
  4834.   Punctuation  marks  are used to help format the data on the screen. The
  4835. comma   divides  the  screen  into  four  columns,  while  the  semicolon
  4836. suppresses  all  spacing.  Either mark can be last symbol on a line. This
  4837. results  in the next thing PRINTed acting as if it were a continuation of
  4838. the same PRINT statement.
  4839.  
  4840.   10 PRINT "HELLO"
  4841.   20 PRINT "HELLO", A$
  4842.   30 PRINT A + B
  4843.   40 PRINT J;
  4844.   50 PRINT A, B, C, D
  4845.  
  4846.   Also see: POS, SPC and TAB functions.
  4847.  
  4848. PRINT#
  4849.  
  4850.   There are a few differences between this statement and PRINT. PRINT# is
  4851. followed by a number,  which refers to the device or data file previously
  4852. OPENed.  This number is followed by a comma and a list to be printed. The
  4853. comma and semicolon have the same effect as they do in PRINT. Please note
  4854. that some devices may not work with TAB and SPC.
  4855.  
  4856.   100 PRINT#1, "DATA VALUES"; A%, B1, C$
  4857.  
  4858. READ
  4859.  
  4860.   READ  is  used to assign information from DATA statements to variables,
  4861. so the information may be put to use. Care must be taken to avoid READing
  4862. strings where READ is expecting a number, which will give a TYPE MISMATCH
  4863. ERROR.
  4864.  
  4865. REM  (Remark)
  4866.  
  4867.   REMark  is a note to whomever is reading a LIST of the program.  It may
  4868. explain  a section of the program,  or give additional instructions.  REM
  4869. statements  in no way affect the operation of the program,  except to add
  4870. to its length. REM may be followed by any text.
  4871.  
  4872. RESTORE
  4873.  
  4874.   When  executed  in  a  program,  the pointer to which an item in a DATA
  4875. statement will be READ next is reset to the first item in the list.  This
  4876. gives you ability to re-READ the information. RESTORE stands by itself on
  4877. a line.
  4878.  
  4879. RETURN
  4880.  
  4881.   This  statement  is  always  used  in conjunction with GOSUB.  When the
  4882. program  encounters  a  RETURN,  it  will go to the statement immediately
  4883. following the GOSUB command.  If no GOSUB was previously issued, a RETURN
  4884. WITHOUT GOSUB ERROR will occur.
  4885.  
  4886. STOP
  4887.  
  4888.   This statement will halt program execution.  The message,  BREAK IN xxx
  4889. will  be  displayed,  where  xxx is the line number containing STOP.  The
  4890. program may be restarted by using the CONT command. STOP is normally used
  4891. in debugging a program.
  4892.  
  4893. SYS
  4894.  
  4895.   SYS  is  followed  by  a  decimal  number or numeric value in the range
  4896. 0-65535.  The  program  will  then  begin  executing the machine language
  4897. program  starting  at  that  memory  location. This is similar to the USR
  4898. function, but does not allow parameter passing.
  4899.  
  4900. WAIT
  4901.  
  4902.   WAIT  is  used  to  halt  the  program  until  the contents of a memory
  4903. location changes in a specific way. WAIT is followed by a memory location
  4904. (X) and up to two variables. The format is:
  4905.  
  4906.   WAIT X,Y,Z
  4907.  
  4908.   The  contents  of the memory location are first exclusive-ORed with the
  4909. third  number,  if  present,  and  then  logically  ANDed with the second
  4910. number.  If  the  result  is  zero,  the program goes back to that memory
  4911. location  and  checks  again.  When  the  result  is nonzero, the program
  4912. continues with the next statement.
  4913.  
  4914.  
  4915.  
  4916. NUMERIC FUNCTIONS
  4917.  
  4918. ABS(X)  (absolute value)
  4919.  
  4920.   ABS  returns  the absolute value of the number,  without its sign (+ or
  4921. -). The answer is always positive.
  4922.  
  4923. ATN(X)  (arctangent)
  4924.  
  4925.   Returns the angle, measured in radians, whose tangent is X.
  4926.  
  4927. COS(X)  (cosine)
  4928.  
  4929.   Returns  the  value of the cosine of X, where X is an angle measured in
  4930. radians.
  4931.  
  4932. EXP(X)
  4933.  
  4934.   Returns the value of the mathematical constant e (2.71827183) raised to
  4935. the power of X.
  4936.  
  4937. FN xx(X)
  4938.  
  4939.   Returns  the  value  of  the  user-defined function xx created in a DEF
  4940. FN xx(X) statement.
  4941.  
  4942. INT(X)
  4943.  
  4944.   Returns the truncated value of X, that is,  with all the decimal places
  4945. to the right of the decimal point removed. The result will always be less
  4946. than, or equal to, X. Thus, any negative numbers with decimal places will
  4947. become the integer less than their current value.
  4948.  
  4949. LOG(X)  (logarithm)
  4950.  
  4951.   Will  return  the natural log of X.  The natural log to the base e (see
  4952. EXP(X)). To convert to log base 10, simply divide by LOG(10).
  4953.  
  4954. PEEK(X)
  4955.  
  4956.   Used  to  find  out  contents  of  memory  location  X,  in  the  range
  4957. 0-65535,  giving  a  result from 0-255. PEEK is often used in conjunction
  4958. with the POKE statement.
  4959.  
  4960. RND(X)  (random number)
  4961.  
  4962.   RND(X)  returns  a  random  number  in  the range 0-1. The first random
  4963. number  should  be  generated by the formula RND(-TI) to start things off
  4964. differently  every  time.  After  this,  X  should be a 1 or any positive
  4965. number.  If  X  is zero, the result will be the same random number as the
  4966. last one.
  4967.   A  negative  value  for  X  will  reseed  the generator. The use of the
  4968. same  negative  number  for  X  will  result  in  the  same  sequence  of
  4969. "random" numbers.
  4970.   The formula for generating a number between X and Y is:
  4971.  
  4972.   N = RND(1) * (Y-X) + X
  4973.  
  4974. where,
  4975.   Y is the upper limit,
  4976.   X is the lower range of numbers desired.
  4977.  
  4978. SGN(X)  (sign)
  4979.  
  4980.   This function returns the sign (positive, negative, or zero) of X.  The
  4981. result will be +1 if positive, 0 if zero, and -1 if negative.
  4982.  
  4983. SIN(X)  (sine)
  4984.  
  4985.   SIN(X) is the trigonometric sine function.  The result will be the sine
  4986. of X, where X is an angle in radians.
  4987.  
  4988. SQR(X)  (square root)
  4989.  
  4990.   This  function will return the square root of X,  where X is a positive
  4991. number or 0. If X is negative, an ILLEGAL QUANTITY ERROR results.
  4992.  
  4993. TAN(X)  (tangent)
  4994.  
  4995.   The result will be the tangent of X, where X is an angle in radians.
  4996.  
  4997. USR(X)
  4998.  
  4999.   When  this  function  is used,  the program jumps to a machine language
  5000. program  whose  starting  point  is  contained  in memory locations.  The
  5001. parameter X is passed to the machine language program,  which will return
  5002. another  value  back  to  the  BASIC  program.  Refer to the Commodore 64
  5003. Programmer's Reference Manual  for  more  details  on  this  function and
  5004. machine language programming.
  5005.  
  5006.  
  5007.  
  5008. STRING FUNCTIONS
  5009.  
  5010. ASC(X$)
  5011.  
  5012.   This function will return the ASCII code of the first character of X$.
  5013.  
  5014. CHR$(X)
  5015.  
  5016.   This is the opposite of ASC, and returns a string character whose ASCII
  5017. code is X.
  5018.  
  5019. LEFT$(X$,X)
  5020.  
  5021.   Returns a string containing the leftmost X characters of X$.
  5022.  
  5023. LEN(X$)
  5024.  
  5025.   Returned will be the number of characters  (including  spaces and other
  5026. symbols) in the string X$.
  5027.  
  5028. MID$(X$,S,X)
  5029.  
  5030.   This will return a string containing X characters starting from the Sth
  5031. character in X$.
  5032.  
  5033. RIGHT$(X$,X)
  5034.  
  5035.   Returns the rightmost X characters in X$.
  5036.  
  5037. STR$(X)
  5038.  
  5039.   This will return a string  which is identical to the PRINTed version of
  5040. X.
  5041.  
  5042. VAL(X$)
  5043.  
  5044.   This function converts X$ into a number, and is essentially the inverse
  5045. operation  from STR$.  The string is examined from the leftmost character
  5046. to  the  right,  for  as  many  characters  as are in recognizable number
  5047. format.
  5048.  
  5049.   10 X = VAL("123.456")             X = 123.456
  5050.   10 X = VAL("12A13B")              X = 12
  5051.   10 X = VAL("RIU017")              X = 0
  5052.   10 X = VAL("-1.23.45.67")         X = -1.23
  5053.  
  5054.  
  5055.  
  5056. OTHER FUNCTIONS
  5057.  
  5058. FRE(X)
  5059.  
  5060.   This  function  returns the number of unused bytes available in memory,
  5061. regardless  of the value of X.  Note that FRE(X) will read out n negative
  5062. numbers if the number of unused bytes is over 32K.
  5063.  
  5064. POS(X)
  5065.  
  5066.   This function returns the number of the column (0-39) at which the next
  5067. PRINT statement will begin on the screen. X may have any value and is not
  5068. used.
  5069.  
  5070. SPC(X)
  5071.  
  5072.   This is used in a PRINT statement to skip X spaces forward.
  5073.  
  5074. TAB(X)
  5075.  
  5076.   TAB is also used in a PRINT statement; the next item to be PRINTed will
  5077. be in column X.
  5078.  
  5079.  
  5080.  
  5081.  
  5082. APPENDIX D
  5083.  
  5084. ABBREVIATIONS FOR BASIC KEYWORDS
  5085.  
  5086.  
  5087.   As  a  time-saver  when  typing  in programs and commands, Commodore 64
  5088. BASIC  allows  the  user  to  abbreviate  most keywords. The abbreviation
  5089. for  PRINT  is  a  question  mark.  The abbreviations for other words are
  5090. made  by  typing  the  first  one or two letters of the word, followed by
  5091. the  SHIFTed  next  letter  of the word. If the abbreviations are used in
  5092. a program line, the keyword will LIST in the full form.
  5093.  
  5094. Com-     Abbrevi-       Looks like  | Com-     Abbrevi-       Looks like
  5095. mand     ation          this on     | mand     ation          this on
  5096.                         screen      |                         screen
  5097. ------------------------------------+------------------------------------
  5098.  ABS     A <SHIFT+B>                |  NOT     N <SHIFT+O>
  5099.  AND     A <SHIFT+N>                |  ON      NONE               ON
  5100.  ASC     A <SHIFT+S>                |  OPEN    O <SHIFT+P>
  5101.  ATN     A <SHIFT+T>                |  OR      NONE               OR
  5102.  CHR$    C <SHIFT+H>                |  PEEK    P <SHIFT+E>
  5103.  CLOSE   CL <SHIFT+O>               |  POKE    P <SHIFT+O>
  5104.  CLR     C <SHIFT+L>                |  POS     NONE               POS
  5105.  CMD     C <SHIFT+M>                |  PRINT   ?                  ?
  5106.  CONT    C <SHIFT+O>                |  PRINT#  P <SHIFT+R>
  5107.  COS     NONE              COS      |  READ    R <SHIFT+E>
  5108.  DATA    D <SHIFT+A>                |  REM     NONE               REM
  5109.  DEF     D <SHIFT+E>                |  RESTORE RE <SHIFT+S>
  5110.  DIM     D <SHIFT+I>                |  RETURN  RE <SHIFT+T>
  5111.  END     E <SHIFT+N>                |  RIGHT$  R <SHIFT+I>
  5112.  EXP     E <SHIFT+X>                |  RND     R <SHIFT+N>
  5113.  FN      NONE              FN       |  RUN     R <SHIFT+U>
  5114.  FOR     F <SHIFT+O>                |  SAVE    S <SHIFT+A>
  5115.  FRE     F <SHIFT+R>                |  SGN     S <SHIFT+G>
  5116.  GET     G <SHIFT+E>                |  SIN     S <SHIFT+I>
  5117.  GET#    NONE              GET#     |  SPC(    S <SHIFT+P>
  5118.  GOSUB   GO <SHIFT+S>               |  SQR     S <SHIFT+Q>
  5119.  GOTO    G <SHIFT+O>                |  STATUS  ST                 ST
  5120.  IF      NONE              IF       |  STEP    ST <SHIFT+E>
  5121.  INPUT   NONE              INPUT    |  STOP    S <SHIFT+T>
  5122.  INPUT#  I <SHIFT+N>                |  STR$    ST <SHIFT+R>
  5123.  INT     NONE              INT      |  SYS     S <SHIFT+Y>
  5124.  LEFT$   LE <SHIFT+F>               |  TAB(    T <SHIFT+A>
  5125.  LEN     NONE              LEN      |  TAN     NONE               TAN
  5126.  LET     L <SHIFT+E>                |  THEN    T <SHIFT+H>
  5127.  LIST    L <SHIFT+I>       SAVE     |  TIME    TI                 TI
  5128.  LOAD    L <SHIFT+O>                |  TIME$   TI$                TI$
  5129.  LOG     NONE              LOG      |  USR     U <SHIFT+S>
  5130.  MID$    M <SHIFT+I>                |  VAL     V <SHIFT+A>
  5131.  NEW     NONE              NEW      |  VERIFY  V <SHIFT+E>
  5132.  NEXT    N <SHIFT+E>                |  WAIT    W <SHIFT+A>
  5133.  
  5134.  
  5135.  
  5136. APPENDIX E
  5137.  
  5138. SCREEN DISPLAY CODES
  5139.  
  5140.  
  5141.   The  following  chart  lists  all  of  the  characters  built  into the
  5142. Commodore  64  character  sets.  It  shows  which numbers should be POKED
  5143. into  screen  memory  (locations  1024-2023)  to get a desired character.
  5144. Also  shown  is  which  character corresponds to a number PEEKed from the
  5145. screen.
  5146.   Two  character  sets  are  available,  but only one set at a time. This
  5147. means  that  you  cannot  have  characters  from one set on the screen at
  5148. the  same  time  you  have  characters  from the other set displayed. The
  5149. sets   are   switched   by   holding  down  the  <SHIFT>  and  <C=>  keys
  5150. simultaneously.
  5151.   From  BASIC,  POKE  53272,21  will  switch  to upper case mode and POKE
  5152. 53272,23 switches to lower case.
  5153.   Any  number  on  the  chart  may  also  be  displayed  in  REVERSE. The
  5154. reverse  character  code  may  be  obtained  by  adding 128 to the values
  5155. shown.
  5156.   If  you  want  to  display  a  solid  circle at location 1504, POKE the
  5157. code for the circle (81) into location 1504: POKE 1504,81.
  5158.   There  is  a  corresponding  memory  location  to  control the color of
  5159. each  character  displayed  on  the  screen  (locations  55296-56295). To
  5160. change  the  color  of the circle to yellow (color code 7) you would POKE
  5161. the  corresponding  memory  location (55776) with the character color:
  5162. POKE 55776,7.
  5163.   Refer  to  Appendix  G  for  the complete screen and color memory maps,
  5164. along with color codes.
  5165.  
  5166. SCREEN CODES
  5167.  
  5168.   SET 1   SET 2   POKE  |  SET 1   SET 2   POKE  |  SET 1   SET 2   POKE
  5169. ------------------------+------------------------+-----------------------
  5170.     @               0   |    +              43   |            V      86
  5171.     A       a       1   |    ,              44   |            W      87
  5172.     B       b       2   |    -              45   |            X      88
  5173.     C       c       3   |    .              46   |            Y      89
  5174.     D       d       4   |    /              47   |            Z      90
  5175.     E       e       5   |    0              48   |                   91
  5176.     F       f       6   |    1              49   |                   92
  5177.     G       g       7   |    2              50   |                   93
  5178.     H       h       8   |    3              51   |                   94
  5179.     I       i       9   |    4              52   |                   95
  5180.     J       j      10   |    5              53   |  SPACE            96
  5181.     K       k      11   |    6              54   |                   97
  5182.     L       l      12   |    7              55   |                   98
  5183.     M       m      13   |    8              56   |                   99
  5184.     N       n      14   |    9              57   |                  100
  5185.     O       o      15   |    :              58   |                  101
  5186.     P       p      16   |    ;              59   |                  102
  5187.     Q       q      17   |    <              60   |                  103
  5188.     R       r      18   |    =              61   |                  104
  5189.     S       s      19   |    >              62   |                  105
  5190.     T       t      20   |    ?              63   |                  106
  5191.     U       u      21   |                   64   |                  107
  5192.     V       v      22   |            A      65   |                  108
  5193.     W       w      23   |            B      66   |                  109
  5194.     X       x      24   |            C      67   |                  110
  5195.     Y       y      25   |            D      68   |                  111
  5196.     Z       z      26   |            E      69   |                  112
  5197.     [              27   |            F      70   |                  113
  5198.   pound            28   |            G      71   |                  114
  5199.     ]              29   |            H      72   |                  115
  5200.     ^              30   |            I      73   |                  116
  5201.     <-             31   |            J      74   |                  117
  5202.   SPACE            32   |            K      75   |                  118
  5203.     !              33   |            L      76   |                  119
  5204.     "              34   |            M      77   |                  120
  5205.     #              35   |            N      78   |                  121
  5206.     $              36   |            O      79   |                  122
  5207.     %              37   |            P      80   |                  123
  5208.     &              38   |            Q      81   |                  124
  5209.     '              39   |            R      82   |                  125
  5210.     (              40   |            S      83   |                  126
  5211.     )              41   |            T      84   |                  127
  5212.     *              42   |            U      85   |
  5213. ------------------------+------------------------+-----------------------
  5214.  
  5215. Codes from 128-255 are reversed images of codes 0-127.
  5216.  
  5217.  
  5218.  
  5219. APPENDIX F
  5220.  
  5221. ASCII AND CHR$ CODES
  5222.  
  5223.  
  5224.   This  appendix  shows  you  what  characters  will  appear if you PRINT
  5225. CHR$(X),  for  all  possible  values  of  X. It will also show the values
  5226. obtained by typing PRINT ASC("x"), where x is any character you can type.
  5227. This  is  useful in evaluating the character received in a GET statement,
  5228. converting upper/lower case,  and printing character based commands (like
  5229. switch to upper/lower case) that could not be enclosed in quotes.
  5230.  
  5231. +-----------------+-----------------+-----------------+-----------------+
  5232. |  PRINTS   CHR$  |  PRINTS   CHR$  |  PRINTS   CHR$  |  PRINTS   CHR$  |
  5233. +-----------------+-----------------+-----------------+-----------------+
  5234. |             0   |    0       48   |            96   | {black}   144   |
  5235. |             1   |    1       49   |            97   |   {up}    145   |
  5236. |             2   |    2       50   |            98   | {rvs off} 146   |
  5237. |             3   |    3       51   |            99   | {clear}   147   |
  5238. |             4   |    4       52   |           100   |  {inst}   148   |
  5239. | {white}     5   |    5       53   |           101   | {brown}   149   |
  5240. |             6   |    6       54   |           102   | {lt. red} 150   |
  5241. |             7   |    7       55   |           103   | {grey 1}  151   |
  5242. | disSHIFT+C= 8   |    8       56   |           104   | {grey 2}  152   |
  5243. | enaSHIFT+C= 9   |    9       57   |           105   | {lt.green}153   |
  5244. |            10   |    :       58   |           106   | {lt.blue} 154   |
  5245. |            11   |    ;       59   |           107   | {grey 3}  155   |
  5246. |            12   |    <       60   |           108   | {purple}  156   |
  5247. | return     13   |    =       61   |           109   | {left}    157   |
  5248. | lower case 14   |    >       62   |           110   | {yellow}  158   |
  5249. |            15   |    ?       63   |           111   |  {cyan}   159   |
  5250. |            16   |    @       64   |           112   |  SPACE    160   |
  5251. |  {down}    17   |    A       65   |           113   |           161   |
  5252. | {rvs on}   18   |    B       66   |           114   |           162   |
  5253. |  {home}    19   |    C       67   |           115   |           163   |
  5254. |  {del}     20   |    D       68   |           116   |           164   |
  5255. |            21   |    E       69   |           117   |           165   |
  5256. |            22   |    F       70   |           118   |           166   |
  5257. |            23   |    G       71   |           119   |           167   |
  5258. |            24   |    H       72   |           120   |           168   |
  5259. |            25   |    I       73   |           121   |           169   |
  5260. |            26   |    J       74   |           122   |           170   |
  5261. |            27   |    K       75   |           123   |           171   |
  5262. |  {red}     28   |    L       76   |           124   |           172   |
  5263. | {right}    29   |    M       77   |           125   |           173   |
  5264. | {green}    30   |    N       78   |           126   |           174   |
  5265. |  {blue}    31   |    O       79   |           127   |           175   |
  5266. |  SPACE     32   |    P       80   |           128   |           176   |
  5267. |    !       33   |    Q       81   | {orange}  129   |           177   |
  5268. |    "       34   |    R       82   |           130   |           178   |
  5269. |    #       35   |    S       83   |           131   |           179   |
  5270. |    $       36   |    T       84   |           132   |           180   |
  5271. |    %       37   |    U       85   |    f1     133   |           181   |
  5272. |    &       38   |    V       86   |    f3     134   |           182   |
  5273. |    '       39   |    W       87   |    f5     135   |           183   |
  5274. |    (       40   |    X       88   |    f7     136   |           184   |
  5275. |    )       41   |    Y       89   |    f2     137   |           185   |
  5276. |    *       42   |    Z       90   |    f4     138   |           186   |
  5277. |    +       43   |    [       91   |    f6     139   |           187   |
  5278. |    ,       44   |  pound     92   |    f8     140   |           188   |
  5279. |    -       45   |    ]       93   |shift+ret. 141   |           189   |
  5280. |    .       46   |    ^       94   |upper case 142   |           190   |
  5281. |    /       47   |{arrow left}95   |           143   |           191   |
  5282. +-----------------+-----------------+-----------------+-----------------+
  5283.  
  5284. CODES 192-223 SAME AS  96-127
  5285. CODES 224-254 SAME AS 160-190
  5286. CODE 255 SAME AS 126
  5287.  
  5288.  
  5289.  
  5290. APPENDIX D
  5291.  
  5292. SCREEN AND COLOR MEMORY MAPS
  5293.  
  5294.  
  5295.   The  following  charts  list  which  memory  locations  control placing
  5296. characters  on  the  screen,  and the locations used to change individual
  5297. character colors, as well as showing character color codes.
  5298.  
  5299.                            SCREEN MEMORY MAP
  5300.  
  5301.                                  COLUMN                             1063
  5302.       0             10             20             30            39 /
  5303.      +------------------------------------------------------------/
  5304. 1024 |                                                            |  0
  5305. 1064 |                                                            |
  5306. 1104 |                                                            |
  5307. 1144 |                                                            |
  5308. 1184 |                                                            |
  5309. 1224 |                                                            |
  5310. 1264 |                                                            |
  5311. 1304 |                                                            |
  5312. 1344 |                                                            |
  5313. 1384 |                                                            |
  5314. 1424 |                                                            | 10
  5315. 1464 |                                                            |
  5316. 1504 |                                                            |   ROW
  5317. 1544 |                                                            |
  5318. 1584 |                                                            |
  5319. 1624 |                                                            |
  5320. 1664 |                                                            |
  5321. 1704 |                                                            |
  5322. 1744 |                                                            |
  5323. 1784 |                                                            |
  5324. 1824 |                                                            | 20
  5325. 1864 |                                                            |
  5326. 1904 |                                                            |
  5327. 1944 |                                                            |
  5328. 1984 |                                                            | 24
  5329.      +------------------------------------------------------------\
  5330.                                                                    \
  5331.                                                                     2023
  5332.  
  5333.   The  actual  values  to  POKE  into a color memory location to change a
  5334. character's color are:
  5335.  
  5336.   0  BLACK                          8  ORANGE
  5337.   1  WHITE                          9  BROWN
  5338.   2  RED                           10  Light RED
  5339.   3  CYAN                          11  GRAY 1
  5340.   4  PURPLE                        12  GRAY 2
  5341.   5  GREEN                         13  Light GREEN
  5342.   6  BLUE                          14  Light BLUE
  5343.   7  YELLOW                        15  GRAY 3
  5344.  
  5345.   For  example,  to  change the color of a character located at the upper
  5346. left-hand corner of the screen to red, type: POKE 55296,2.
  5347.  
  5348.                             COLOR MEMORY MAP
  5349.  
  5350.                                  COLUMN                             55335
  5351.       0             10             20             30            39 /
  5352.      +------------------------------------------------------------/
  5353. 55296|                                                            |  0
  5354. 55336|                                                            |
  5355. 55376|                                                            |
  5356. 55416|                                                            |
  5357. 55456|                                                            |
  5358. 55496|                                                            |
  5359. 55536|                                                            |
  5360. 55576|                                                            |
  5361. 55616|                                                            |
  5362. 55656|                                                            |
  5363. 55696|                                                            | 10
  5364. 55736|                                                            |
  5365. 55776|                                                            |   ROW
  5366. 55816|                                                            |
  5367. 55856|                                                            |
  5368. 55896|                                                            |
  5369. 55936|                                                            |
  5370. 55976|                                                            |
  5371. 56016|                                                            |
  5372. 56056|                                                            |
  5373. 56096|                                                            | 20
  5374. 56136|                                                            |
  5375. 56176|                                                            |
  5376. 56216|                                                            |
  5377. 56256|                                                            | 24
  5378.      +------------------------------------------------------------\
  5379.                                                                    56295
  5380.  
  5381.  
  5382.  
  5383. APPENDIX H
  5384.  
  5385. DERIVING MATHEMATICAL FUNCTIONS
  5386.  
  5387.  
  5388.   Functions  that  are  not  intrinsic  to  Commodore  64  BASIC  may  be
  5389. calculated as follows:
  5390.  
  5391. +-------------------------------+---------------------------------------+
  5392. |           FUNCTION            |            BASIC EQUIVALENT           |
  5393. +-------------------------------+---------------------------------------+
  5394. | SECANT                        | SEC(X)=1/COS(X)                       |
  5395. | COSECANT                      | CSC(X)=1/SIN(X)                       |
  5396. | COTANGENT                     | COT(X)=1/TAN(X)                       |
  5397. | INVERSE SINE                  | ARCSIN(X)=ATN(X/SQR(-X*X+1))          |
  5398. | INVERSE COSINE                | ARCCOS(X)=-ATN(X/SQR(-X*X+1))+{pi}/2  |
  5399. | INVERSE SECANT                | ARCSEC(X)=ATN(X/SQR(X*X-1))           |
  5400. | INVERSE COSECANT              | ARCCSC(X)=ATN(X/SQR(X*X-1))           |
  5401. |                               |   +(SGN(X)-1*{pi}/2                   |
  5402. | INVERSE COTANGENT             | ARCOT(X)=ATN(X)+{pi}/2                |
  5403. | HYPERBOLIC SINE               | SINH(X)=(EXP(X)-EXP(-X))/2            |
  5404. | HYPERBOLIC COSINE             | COSH(X)=(EXP(X)+EXP(-X))/2            |
  5405. | HYPERBOLIC TANGENT            | TANH(X)=EXP(-X)/(EXP(X)+EXP(-X))*2+1  |
  5406. | HYPERBOLIC SECANT             | SECH(X)=2/(EXP(X)+EXP(-X))            |
  5407. | HYPERBOLIC COSECANT           | CSCH(X)=2/(EXP(X)-EXP(-X))            |
  5408. | HYPERBOLIC  COTANGENT         | COTH(X)=EXP(-X)/(EXP(X)-EXP(-X))*2+1  |
  5409. | INVERSE HYPERBOLIC SINE       | ARCSINH(X)=LOG(X+SQR(X*X+1))          |
  5410. | INVERSE HYPERBOLIC COSINE     | ARCCOSH(X)=LOG(X+SQR(X*X-1))          |
  5411. | INVERSE HYPERBOLIC TANGENT    | ARCTANH(X)=LOG((1+X)/(1-X))/2         |
  5412. | INVERSE HYPERBOLIC SECANT     | ARCSECH(X)=LOG((SQR(-X*X+1)+1/X)      |
  5413. | INVERSE HYPERBOLIC COSECANT   | ARCCSCH(X)=LOG((SGN(X)*SQR(X*X+1/X)   |
  5414. | INVERSE HYPERBOLIC COTANGENT  | ARCCOTH(X)=LOG((X+1)/(X-1))/2         |
  5415. +------------------------------+----------------------------------------+
  5416.  
  5417.  
  5418.  
  5419. APPENDIX I
  5420.  
  5421. PINOUTS FOR INPUT/OUTPUT DEVICES
  5422.  
  5423.  
  5424.   This  appendix  is designed to show you what connections may be made to
  5425. the Commodore 64.
  5426.  
  5427. 1) Game I/O                        4) Serial I/O (Disk/Printer)
  5428. 2) Cartridge Slot                  5) Modulator Output
  5429. 3) Audio/Video                     6) Cassette
  5430.                                    7) User Port
  5431.  
  5432.  
  5433. Control Port 1
  5434. +-----+-------------+-----------+         /---------------------\
  5435. | Pin |    Type     |   Note    |         |  1   2   3   4   5  |
  5436. +-----+-------------+-----------+         |  O   O   O   O   O  |
  5437. |  1  |    JOYA0    |           |          |                   |
  5438. |  2  |    JOYA1    |           |          |   O   O   O   O   |
  5439. |  3  |    JOYA2    |           |           |  6   7   8   9  |
  5440. |  4  |    JOYA3    |           |            \_______________/
  5441. |  5  |    POT AY   |           |
  5442. |  6  | BUTTON A/LP |           |
  5443. |  7  |     +5V     | MAX. 50mA |
  5444. |  8  |     GND     |           |
  5445. |  9  |   POT AX    |           |
  5446. +-----+-------------+-----------+
  5447.  
  5448. Control Port 2
  5449. +-----+-------------+-----------+
  5450. | Pin |    Type     |   Note    |
  5451. +-----+-------------+-----------+
  5452. |  1  |    JOYB0    |           |
  5453. |  2  |    JOYB1    |           |
  5454. |  3  |    JOYB2    |           |
  5455. |  4  |    JOYB3    |           |
  5456. |  5  |    POT BY   |           |
  5457. |  6  |  BUTTON B   |           |
  5458. |  7  |     +5V     | MAX. 50mA |
  5459. |  8  |     GND     |           |
  5460. |  9  |   POT BX    |           |
  5461. +-----+-------------+-----------+
  5462.  
  5463.  
  5464. Cartridge Expansion Slot
  5465. +--------+-----------+                         +--------+--------------+
  5466. |  Pin   |    Type   |                         |   Pin  |     Type     |
  5467. +--------+-----------+                         +--------+--------------+
  5468. |   12   |   BA      |                         |    1   |   GND        |
  5469. |   13   |   /DMA    |                         |    2   |   +5V        |
  5470. |   14   |   D7      |                         |    3   |   +5V        |
  5471. |   15   |   D6      |                         |    4   |   /IRQ       |
  5472. |   16   |   D5      |                         |    5   |   R/W        |
  5473. |   17   |   D4      |                         |    6   |   Dot Clock  |
  5474. |   18   |   D3      |                         |    7   |   I/O1       |
  5475. |   19   |   D2      |                         |    8   |   /GAME      |
  5476. |   20   |   D1      |                         |    9   |   /EXROM     |
  5477. |   21   |   D0      |                         |   10   |   I/O2       |
  5478. |   22   |   GND     |                         |   11   |   /ROML      |
  5479. +--------+-----------+                         +--------+--------------+
  5480.  
  5481. +--------+-----------+                         +--------+--------------+
  5482. |  Pin   |    Type   |                         |   Pin  |     Type     |
  5483. +--------+-----------+                         +--------+--------------+
  5484. |   N    |   A9      |                         |   A    |   GND        |
  5485. |   P    |   A8      |                         |   B    |   /ROMH      |
  5486. |   R    |   A7      |                         |   C    |   /RESET     |
  5487. |   S    |   A6      |                         |   D    |   /NMI       |
  5488. |   T    |   A5      |                         |   E    |   02         |
  5489. |   U    |   A4      |                         |   F    |   A15        |
  5490. |   V    |   A3      |                         |   H    |   A14        |
  5491. |   W    |   A2      |                         |   J    |   A13        |
  5492. |   X    |   A1      |                         |   K    |   A12        |
  5493. |   Y    |   A0      |                         |   L    |   A11        |
  5494. |   Z    |   GND     |                         |   M    |   A10        |
  5495. +--------+-----------+                         +--------+--------------+
  5496.  
  5497.     2 2 2 1 1 1 1 1 1 1 1 1 1
  5498.     2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1
  5499. +---@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@---+
  5500. |                                                 |
  5501. +---@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@---+
  5502.     Z Y X W V U T S R P N M L K J H F E D C B A
  5503.  
  5504.  
  5505. Audio/Video                                                ++ ++
  5506. +--------------------------+------------------+           / +-+ \
  5507. |   Pin  |      Type       |       Note       |          /       \
  5508. +--------+-----------------+------------------+         +         +
  5509. |    1   |  LUMINANCE      |                  |         |3O     O1|
  5510. |    2   |  GND            |                  |         |         |
  5511. |    3   |  AUDIO OUT      |                  |         +  O   O  +
  5512. |    4   |  VIDEO OUT      |                  |          \5  O  4/
  5513. |    5   |  AUDIO IN       |                  |           \  2  /
  5514. +--------+-----------------+------------------+            +---+
  5515.  
  5516.  
  5517. Serial I/O                                                 ++ ++
  5518. +---------------------------------------------+           / +-+ \
  5519. |   Pin  |                Type                |          /5     1\
  5520. +--------+------------------------------------+         +  O   O  +
  5521. |    1   |  SERIAL /SRQIN                     |         |    6    |
  5522. |    2   |  GND                               |         |    O    |
  5523. |    3   |  SERIAL ATN OUT                    |         |         |
  5524. |    4   |  SERIAL CLK IN/OUT                 |         +  O   O  +
  5525. |    5   |  SERIAL DATA IN/OUT                |          \4  O  2/
  5526. |    6   |  /RESET                            |           \  3  /
  5527. +--------+------------------------------------+            +---+
  5528.  
  5529.  
  5530. Cassette
  5531. +-------+-------------------------------------+
  5532. |  Pin  |                Type                 |
  5533. +-------+-------------------------------------+
  5534. |  A-1  |  GND                                |         1 2 3 4 5 6
  5535. |  B-2  |  +5V                                |     +---@-@-@-@-@-@---+
  5536. |  C-3  |  CASSETTE MOTOR                     |     |                 |
  5537. |  D-4  |  CASSETTE READ                      |     +---@-@-@-@-@-@---+
  5538. |  E-5  |  CASSETTE WRITE                     |         A B C D E F
  5539. |  F-6  |  CASSETTE SENSE                     |
  5540. +-------+-------------------------------------+
  5541.  
  5542.  
  5543. User I/O
  5544. +------+------------------+-------------------+
  5545. |  Pin |       Type       |       Note        |
  5546. +------+------------------+-------------------+
  5547. |   1  |  GND             |                   |
  5548. |   2  |  +5V             | MAX. 100 mA       |
  5549. |   3  |  /RESET          |                   |
  5550. |   4  |  CNT1            |                   |
  5551. |   5  |  SP1             |                   |
  5552. |   6  |  CNT2            |                   |
  5553. |   7  |  SP2             |                   |
  5554. |   8  |  /PC2            |                   |
  5555. |   9  |  SER. ATN OUT    |                   |
  5556. |  10  |  9 VAC           | MAX. 100 mA       |
  5557. |  11  |  9 VAC           | MAX. 100 mA       |
  5558. |  12  |  GND             |                   |
  5559. +------+------------------+-------------------+
  5560.  
  5561. +------+------------------+-------------------+
  5562. |  Pin |      Type        |       Note        |
  5563. +------+------------------+-------------------+
  5564. |   A  |  GND             |                   |
  5565. |   B  |  /FLAG2          |                   |
  5566. |   C  |  PB0             |                   |
  5567. |   D  |  PB1             |                   |
  5568. |   E  |  PB2             |                   |
  5569. |   F  |  PB3             |                   |
  5570. |   H  |  PB4             |                   |
  5571. |   I  |  PB5             |                   |
  5572. |   K  |  PB6             |                   |
  5573. |   L  |  PB7             |                   |
  5574. |   M  |  PA2             |                   |
  5575. |   N  |  GND             |                   |
  5576. +------+------------------+-------------------+
  5577.  
  5578.                      1 1 1
  5579.    1 2 3 4 5 6 7 8 9 0 1 2
  5580. +--@-@-@-@-@-@-@-@-@-@-@-@--+
  5581. |                           |
  5582. +--@-@-@-@-@-@-@-@-@-@-@-@--+
  5583.    A B C D E F H J K L M N
  5584.  
  5585.  
  5586.  
  5587. APPENDIX J
  5588.  
  5589.  
  5590. PROGRAMS TO TRY
  5591.  
  5592.   We've  included  a  number  of useful programs for you to try with your
  5593. Commodore 64. These programs will prove both entertaining and useful.
  5594.  
  5595.  
  5596. start tok64 jotto.prg
  5597.  100 print "{down}jotto{space*7}jim butterfield"
  5598.  120 input "{down}want instructions";z$:if asc(z$)=78 goto 250
  5599.  130 print "{down}try to guess the mystery 5-letter word"
  5600.  140 print "{down}you must guess only legal 5-letter"
  5601.  150 print "words, too..."
  5602.  160 print "you will be told the number of matches"
  5603.  170 print "(or 'jots') of your guess."
  5604.  180 print "{down}hint: the trick is to vary slightly"
  5605.  190 print "  from one guess to the next; so that"
  5606.  200 print "  if you guess 'batch' and get 2 jots"
  5607.  210 print "  you might try 'botch' or 'chart'"
  5608.  220 print "  for the next guess..."
  5609.  250 data bxbsf,ipccz,dbdif,esfbe,pggbm
  5610.  260 data hpshf,ibudi,djwjm,kpmmz,lbzbl
  5611.  270 data sbkbi,mfwfm,njnjd,boofy,qjqfs
  5612.  280 data rvftu,sjwfs,qsftt,puufs,fwfou
  5613.  290 data xfbwf,fyupm,nvtiz,afcsb,gjaaz
  5614.  300 data uijdl,esvol,gmppe,ujhfs,gblfs
  5615.  310 data cppui,mzjoh,trvbu,hbvaf,pxjoh
  5616.  320 data uisff,tjhiu,bymft,hsvnq,bsfob
  5617.  330 data rvbsu,dsffq,cfmdi,qsftt,tqbsl
  5618.  340 data sbebs,svsbm,tnfmm,gspxo,esjgu
  5619.  400 n=50
  5620.  410 dim n$(n),z(5),y(5)
  5621.  420 for j=1 to n: read n$(j): next j
  5622.  430 t=ti
  5623.  440 t=t/1000:if t>=1 then goto 440
  5624.  450 z=rnd(-t)
  5625.  500 g=0: n$=n$(rnd(1)*n+1)
  5626.  510 print "{down}i have a five letter word:": if r>0 then 560
  5627.  520 print "guess (with legal words)"
  5628.  530 print "and i'll tell you how many"
  5629.  540 print "'jots', or matching letters,"
  5630.  550 print "you have...."
  5631.  560 g=g+1: input "your word";z$
  5632.  570 if len(z$)<>5 then print "you must guess a 5-letter word!": goto 560
  5633.  580 v=0: h=0: m=0
  5634.  590 for j=1 to 5
  5635.  600 z=asc(mid$(z$,j,1)): y=asc(mid$(n$,j,1))-1: if y=64 then y=90
  5636.  610 if z<65 or z>90 then print "that's not a word!": goto 560
  5637.  620 if z=65 or z=69 or z=73 or z=79 or z=85 or z=89 then v=v+1
  5638.  630 if z=y then m=m+1
  5639.  640 z(j)=z: y(j)=y: next j
  5640.  650 if m=5 goto 800
  5641.  660 if v=0 or v=5 then print "come on..what kind of a word is that?":\
  5642.      goto 560
  5643.  670 for j=1 to 5: y=y(j)
  5644.  680 for k=1 to 5: if y=z(k) then h=h+1:z(k)=0:goto 700
  5645.  690 next k
  5646.  700 next j
  5647.  710 print"{up}{right*19}";h;"jots"
  5648.  720 if g<30 goto 560
  5649.  730 print "i'd better tell you.. word was '";
  5650.  740 for j=1 to 5: print chr$(y(j));: next j
  5651.  750 print"'": goto 810
  5652.  800 print "you got it in only";g;"guesses."
  5653.  810 input "{down}another word";z$
  5654.  820 r=1: if asc(z$)<>78 goto 500
  5655. stop tok64
  5656.  
  5657. begin 644 jotto.prg
  5658. M`0@F"&0`F2`B$4I/5%1/("`@("`@($I)32!"551415)&245,1"(`50AX`(4@
  5659. M(A%704Y4($E.4U1254-424].4R([6B0ZBR#&*%HD*;(W."")(#(U,`"%"((`
  5660. MF2`B$51262!43R!'54534R!42$4@35E35$5262`U+4Q%5%1%4B!73U)$(@"Q
  5661. M"(P`F2`B$5E/52!-55-4($=515-3($].3%D@3$5'04P@-2U,151415(B`,<(
  5662. ME@"9(")73U)$4RP@5$]/+BXN(@#V"*``F2`B64]5(%=)3$P@0D4@5$],1"!4
  5663. M2$4@3E5-0D52($]&($U!5$-(15,B`!D)J@"9("(H3U(@)TI/5%,G*2!/1B!9
  5664. M3U52($=515-3+B(`1@FT`)D@(A%(24Y4.B!42$4@5%))0TL@25,@5$\@5D%2
  5665. M62!33$E'2%1,62(`=`F^`)D@(B`@1E)/32!/3D4@1U5%4U,@5$\@5$A%($Y%
  5666. M6%0[(%-/(%1(050B`*()R`"9("(@($E&(%E/52!'54534R`G0D%40T@G($%.
  5667. M1"!'150@,B!*3U13(@#-"=(`F2`B("!93U4@34E'2%0@5%)9("="3U1#2"<@
  5668. M3U(@)T-(05)4)R(`[0G<`)D@(B`@1D]2(%1(12!.15A4($=515-3+BXN(@`1
  5669. M"OH`@R!"6$)31BQ)4$-#6BQ$0D1)1BQ%4T9"12Q01T="30`U"@0!@R!(4%-(
  5670. M1BQ)0E5$22Q$2E=*32Q+4$U-6BQ,0EI"3`!9"@X!@R!30DM"22Q-1E=&32Q.
  5671. M2DY*1"Q"3T]&62Q12E%&4P!]"A@!@R!25D9452Q32E=&4RQ14T945"Q0555&
  5672. M4RQ&5T9/50"A"B(!@R!81D)71BQ&655032Q.5E1)6BQ!1D-30BQ'2D%!6@#%
  5673. M"BP!@R!524I$3"Q%4U9/3"Q'35!012Q52DA&4RQ'0DQ&4P#I"C8!@R!#4%!5
  5674. M22Q-6DI/2"Q44E9"52Q(0E9!1BQ06$I/2``-"T`!@R!525-&1BQ42DA)52Q"
  5675. M64U&5"Q(4U9.42Q"4T9/0@`Q"TH!@R!25D)352Q$4T9&42Q#1DU$22Q14T94
  5676. M5"Q444)33`!5"U0!@R!30D5"4RQ35E-"32Q43D9-32Q'4U!83RQ%4TI'50!>
  5677. M"Y`!3K(U,`!T"YH!AB!.)"A.*2Q:*#4I+%DH-2D`D`ND`8$@2K(Q(*0@3CH@
  5678. MAR!.)"A**3H@@B!*`)D+K@%4LE1)`+4+N`%4LE2M,3`P,#J+(%2QLC$@IR")
  5679. M(#0T,`#!"\(!6K*[**M4*0#:"_0!1[(P.B!.)+).)"B[*#$IK$ZJ,2D`"PS^
  5680. M`9D@(A%)($A!5D4@02!&259%($Q%5%1%4B!73U)$.B(Z((L@4K$P(*<@-38P
  5681. M`"P,"`*9(")'54534R`H5TE42"!,14=!3"!73U)$4RDB`$\,$@*9(")!3D0@
  5682. M22=,3"!414Q,(%E/52!(3U<@34%.62(`=`P<`ID@(B=*3U13)RP@3U(@34%4
  5683. M0TA)3D<@3$545$524RPB`(D,)@*9(")93U4@2$%612XN+BXB`*4,,`)'LD>J
  5684. M,3H@A2`B64]54B!73U)$(CM:)`#A##H"BR##*%HD*;.Q-2"G()D@(EE/52!-
  5685. M55-4($=515-3($$@-2U,151415(@5T]21"$B.B")(#4V,`#S#$0"5K(P.B!(
  5686. MLC`Z($VR,``!#4X"@2!*LC$@I"`U`#4-6`):LL8HRBA:)"Q*+#$I*3H@6;+&
  5687. M*,HH3B0L2BPQ*2FK,3H@BR!9LC8T(*<@6;(Y,`!G#6("BR!:LS8U(+`@6K$Y
  5688. M,""G()D@(E1(050G4R!.3U0@02!73U)$(2(Z((D@-38P`)T-;`*+(%JR-C4@
  5689. ML"!:LC8Y(+`@6K(W,R"P(%JR-SD@L"!:LC@U(+`@6K(X.2"G(%:R5JHQ`*\-
  5690. M=@*+(%JR62"G($VR3:HQ`,<-@`):*$HILEHZ(%DH2BFR63H@@B!*`-<-B@*+
  5691. M($VR-2")(#@P,``:#I0"BR!6LC`@L"!6LC4@IR"9(")#3TU%($].+BY72$%4
  5692. M($M)3D0@3T8@02!73U)$($E3(%1(050_(CH@B2`U-C``,`Z>`H$@2K(Q(*0@
  5693. M-3H@6;)9*$HI`%T.J`*!($NR,2"D(#4Z((L@6;):*$LI(*<@2+)(JC$Z6BA+
  5694. M*;(P.HD@-S`P`&4.L@*"($L`;0Z\`H(@2@"2#L8"F2*1'1T='1T='1T='1T=
  5695. M'1T='1T='2([2#LB2D]44R(`HP[0`HL@1[,S,"")(#4V,`#-#MH"F2`B22=$
  5696. M($)%5%1%4B!414Q,(%E/52XN(%=/4D0@5T%3("<B.P#L#N0"@2!*LC$@I"`U
  5697. M.B"9(,<H62A**2D[.B""($H`_`[N`IDB)R(Z((D@.#$P`"0/(`.9(")93U4@
  5698. M1T]4($E4($E.($].3%DB.T<[(D=515-315,N(@`]#RH#A2`B$4%.3U1(15(@
  5699. F5T]21"([6B0`6`\T`U*R,3H@BR#&*%HD*;.Q-S@@B2`U,#``````
  5700. `
  5701. end
  5702.  
  5703.  
  5704. start tok64 sequence.prg
  5705.  1 rem *** sequence
  5706.  2 rem
  5707.  3 rem *** from pet user group
  5708.  4 rem *** software exchange
  5709.  5 rem *** po box 371
  5710.  6 rem *** montgomeryville, pa 18936
  5711.  7 rem ***
  5712.  50 dim a$(26)
  5713.  100 z$="abcdefghijklmnopqrstuvwxyz"
  5714.  110 z1$="12345678901234567890123456"
  5715.  200 print "{clear}{down*2}enter length of string to be sequenced{down}"
  5716.  220 input "maximum length is 26 ";s%
  5717.  230 if s%<1 or s%>26 then 200
  5718.  240 s=s%
  5719.  300 for i=1 to s
  5720.  310 a$(i)=mid$(z$,i,1)
  5721.  320 next i
  5722.  400 rem randomize string
  5723.  420 for i=1 to s
  5724.  430 k=int(rnd(1)*s+1)
  5725.  440 t$=a$(i)
  5726.  450 a$(i)=a$(k)
  5727.  460 a$(k)=t$
  5728.  470 next i
  5729.  480 gosub 950
  5730.  595 t=0
  5731.  600 rem rverse substring
  5732.  605 t=t+1
  5733.  610 input "how many to reverse ";r%
  5734.  620 if r%=0 goto 900
  5735.  630 if r%>0 and r%<=s goto 650
  5736.  640 print "must be between 1 and ";s: goto 610
  5737.  650 r=int(r%/2)
  5738.  660 for i=1 to r
  5739.  670 t$=a$(i)
  5740.  680 a$(i)=a$(r%-i+1)
  5741.  690 a$(r%-i+1)=t$
  5742.  700 next i
  5743.  750 gosub 950
  5744.  800 c=1: for i=2 to s
  5745.  810 if a$(i)>a$(i+1) goto 830
  5746.  820 c=0
  5747.  830 next i
  5748.  840 if c=0 goto 600
  5749.  850 print "{down}you did it in ";t;" tries"
  5750.  900 rem check for another game
  5751.  910 input "{down}want to play again ";y$
  5752.  920 if left$(y$,1)="y" or y$="ok" or y$="1" goto 200
  5753.  930 end
  5754.  950 print
  5755.  960 print left$(z1$,s)
  5756.  970 for i=1 to s: print a$(i);: next i
  5757.  980 print "{down}"
  5758.  990 return
  5759. stop tok64
  5760.  
  5761. begin 644 sequence.prg
  5762. M`0@4"`$`CR`J*BH@4T51545.0T4`&@@"`(\`.`@#`(\@*BHJ($923TT@4$54
  5763. M(%5315(@1U)/55``5`@$`(\@*BHJ(%-/1E1705)%($580TA!3D=%`&D(!0"/
  5764. M("HJ*B!03R!"3U@@,S<Q`(T(!@"/("HJ*B!-3TY41T]-15)95DE,3$4L(%!!
  5765. M(#$X.3,V`)<(!P"/("HJ*@"D"#(`AB!!)"@R-BD`R`AD`%HDLB)!0D-$149'
  5766. M2$E*2TQ-3D]045)35%565UA96B(`[0AN`%HQ)+(B,3(S-#4V-S@Y,#$R,S0U
  5767. M-C<X.3`Q,C,T-38B`"`)R`"9("*3$1%%3E1%4B!,14Y'5$@@3T8@4U1224Y'
  5768. M(%1/($)%(%-%455%3D-%1!$B`$$)W`"%(")-05A)355-($Q%3D=42"!)4R`R
  5769. M-B`B.U,E`%H)Y@"+(%,ELS$@L"!3);$R-B"G(#(P,`!C"?``4[)3)0!Q"2P!
  5770. M@2!)LC$@I"!3`(4)-@%!)"A)*;+**%HD+$DL,2D`C0E``8(@20"D"9`!CR!2
  5771. M04Y$3TU)6D4@4U1224Y'`+()I`&!($FR,2"D(%,`Q`FN`4NRM2B[*#$IK%.J
  5772. M,2D`T0FX`50DLD$D*$DI`.$)P@%!)"A)*;)!)"A+*0#N"<P!020H2RFR5"0`
  5773. M]@G6`8(@20``"N`!C2`Y-3``"`I3`E2R,``?"E@"CR!25D524T4@4U5"4U12
  5774. M24Y'`"D*70)4LE2J,0!)"F("A2`B2$]7($U!3ED@5$\@4D5615)312`B.U(E
  5775. M`%H*;`*+(%(ELC`@B2`Y,#``<PIV`HL@4B6Q,""O(%(EL[)3((D@-C4P`)L*
  5776. M@`*9(")-55-4($)%($)%5%=%14X@,2!!3D0@(CM3.B")(#8Q,`"I"HH"4K*U
  5777. M*%(EK3(I`+<*E`*!($FR,2"D(%(`Q`J>`E0DLD$D*$DI`-D*J`)!)"A)*;)!
  5778. M)"A2):M)JC$I`.L*L@)!)"A2):M)JC$ILE0D`/,*O`*"($D`_0KN`HT@.34P
  5779. M`!`+(`-#LC$Z(($@2;(R(*0@4P`J"RH#BR!!)"A)*;%!)"A)JC$I((D@.#,P
  5780. M`#(+-`-#LC``.@L^`X(@20!*"T@#BR!#LC`@B2`V,#``;0M2`YD@(A%93U4@
  5781. M1$E$($E4($E.("([5#LB(%122453(@"*"X0#CR!#2$5#2R!&3U(@04Y/5$A%
  5782. M4B!'04U%`*H+C@.%("(15T%.5"!43R!03$%9($%'04E.("([620`U0N8`XL@
  5783. MR"A9)"PQ*;(B62(@L"!9)+(B3TLB(+`@622R(C$B((D@,C`P`-L+H@.``.$+
  5784. MM@.9`/`+P`.9(,@H6C$D+%,I``T,R@.!($FR,2"D(%,Z()D@020H22D[.B""
  5785. 5($D`%PS4`YD@(A$B`!T,W@..````
  5786. `
  5787. end
  5788.  
  5789.  
  5790. start tok64 pianokey.prg
  5791.  90 REM piano keyboard
  5792.  100 PRINT"{CLEAR} {REVERSE ON} {RIGHT} {RIGHT} {194} {RIGHT} {RIGHT} \
  5793.      {RIGHT} {194} {RIGHT} {RIGHT} {194} {RIGHT} {RIGHT} "
  5794.  110 PRINT" {REVERSE ON} {RIGHT} {RIGHT} {194} {RIGHT} {RIGHT} {RIGHT} \
  5795.      {194} {RIGHT} {RIGHT} {194} {RIGHT} {RIGHT} "
  5796.  120 PRINT" {REVERSE ON} {RIGHT} {RIGHT} {194} {RIGHT} {RIGHT} {RIGHT} \
  5797.      {194} {RIGHT} {RIGHT} {194} {RIGHT} {RIGHT} "
  5798.  130 PRINT" {REVERSE ON} {194} {194} {194} {194} {194} {194} {194} \
  5799.      {194} {194} {194} {194} {194} "
  5800.  140 PRINT" {REVERSE ON}q{194}w{194}e{194}r{194}t{194}y{194}u{194} \
  5801.      i{194}o{194}p{194}@{194}*{194}^"
  5802.  150 PRINT"{DOWN}'space' for solo or polyphonic"
  5803.  160 PRINT"{DOWN}'f1,f3,f5,f7' octave selection"
  5804.  170 PRINT"{DOWN}'f2,f4,f6,f8' waveform{DOWN}"
  5805.  180 PRINT"hang on, setting up frequency table..."
  5806.  190 S=13*4096+1024: DIM F(26): DIM K(255)
  5807.  200 FOR I=0 TO 28: POKE S+I,0: NEXT
  5808.  210 F1=7040: FOR I=1 TO 26: F(27-I)=F1*5.8+30: F1=F1/2^(1/12): NEXT
  5809.  220 K$="q2w3er5t6y7ui9o0p@-*\^"
  5810.  230 FOR I=1 TO LEN(K$): K(ASC(MID$(K$,I)))=I: NEXT
  5811.  240 PRINT "{UP}{SPACE*38}"
  5812.  250 AT=0:DE=0:SU=15:RE=9:SV=SU*16+RE:AV=AT*16+DE:WV=16:W=0:M=1:OC=4:\
  5813.      HB=256:Z=0
  5814.  260 FOR I=0 TO 2: POKE S+5+I*7,AT*16+DE: POKES+6+I*7,SU*16+RE
  5815.  270 POKE S+2+I*7,4000 AND 255: POKE S+3+I*7,4000/256: NEXT
  5816.  280 POKE S+24,15: REM+16+64:poke s+23,7
  5817.  300 GET A$:IF A$="" THEN 300
  5818.  310 FR=F(K(ASC(A$)))/M: T=V*7: CR=S+T+4: IF FR=Z THEN 500
  5819.  320 POKE S+6+T,Z: REM finish dec/sus
  5820.  325 POKE S+5+T,Z: REM finish att/rel
  5821.  330 POKE CR,8: POKE CR,0: REM fix off
  5822.  340 POKE S+T,FR-HB*INT(FR/HB): REM set lo
  5823.  350 POKE S+1+T,FR/HB: REM set hi
  5824.  360 POKE S+6+T,SV: REM set dec/sus
  5825.  365 POKE S+5+T,AV: REM set att/rel
  5826.  370 POKE CR,WV+1: FOR I=1 TO 50*AT: NEXT
  5827.  375 POKE CR,WV: REM pulse
  5828.  380 IF P=1 THEN V=V+1: IF V=3 THEN V=0
  5829.  400 GOTO 300
  5830.  500 IF A$="{F1}" THEN M=1: OC=4: GOTO 300
  5831.  510 IF A$="{F3}" THEN M=2: OC=3: GOTO 300
  5832.  520 IF A$="{F5}" THEN M=4: OC=2: GOTO 300
  5833.  530 IF A$="{F7}" THEN M=8: OC=1: GOTO 300
  5834.  540 IF A$="{F2}" THEN W=0: WV=16: GOTO 300
  5835.  550 IF A$="{F4}" THEN W=1: WV=32: GOTO 300
  5836.  560 IF A$="{F6}" THEN W=2: WV=64: GOTO300
  5837.  570 IF A$="{F8}" THEN W=3: WV=128: GOTO300
  5838.  580 IF A$=" " THEN P=1-P: GOTO 300
  5839.  590 IF A$="{CLEAR}" THEN 200
  5840.  600 GOTO 300
  5841.  800 PRINT"hit a key"
  5842.  810 GET A$: IF A$="" THEN 810: WAIT FOR A KEY
  5843.  820 PRINT A$: RETURN
  5844. stop tok64
  5845.  
  5846. begin 644 pianokey.prg
  5847. M`0@6"%H`CR!024%.3R!+15E"3T%21``Z"&0`F2*3(!(@'2`=(,(@'2`=(!T@
  5848. MPB`=(!T@PB`=(!T@(@!="&X`F2(@$B`=(!T@PB`=(!T@'2#"(!T@'2#"(!T@
  5849. M'2`B`(`(>`"9(B`2(!T@'2#"(!T@'2`=(,(@'2`=(,(@'2`=("(`HPB"`)DB
  5850. M(!(@PB#"(,(@PB#"(,(@PB#"(,(@PB#"(,(@(@#&"(P`F2(@$E'"5\)%PE+"
  5851. M5,)9PE7"2<)/PE#"0,(JPEXB`.T(E@"9(A$G4U!!0T4G($9/4B!33TQ/($]2
  5852. M(%!/3%E02$].24,B`!0)H`"9(A$G1C$L1C,L1C4L1C<G($]#5$%612!314Q%
  5853. M0U1)3TXB`#0)J@"9(A$G1C(L1C0L1C8L1C@G(%=!5D5&3U)-$2(`8@FT`)DB
  5854. M2$%.1R!/3BP@4T545$E.1R!54"!&4D51545.0UD@5$%"3$4N+BXB`(@)O@!3
  5855. MLC$SK#0P.3:J,3`R-#H@AB!&*#(V*3H@AB!+*#(U-2D`HPG(`($@2;(P(*0@
  5856. M,C@Z()<@4ZI)+#`Z(((`X0G2`$8QLC<P-#`Z(($@2;(Q(*0@,C8Z($8H,C>K
  5857. M22FR1C&L-2XXJC,P.B!&,;)&,:TRKB@QK3$R*3H@@@`!"MP`2R2R(E$R5S-%
  5858. M4C54-EDW54DY3S!00"TJ7%XB`"<*Y@"!($FR,2"D(,,H2R0I.B!+*,8HRBA+
  5859. M)"Q)*2DILDDZ(((`5PKP`)D@(I$@("`@("`@("`@("`@("`@("`@("`@("`@
  5860. M("`@("`@("`@("`@("(`I@KZ`$%4LC`Z1$6R,#I35;(Q-3I21;(Y.E-6LE-5
  5861. MK#$VJE)%.D%6LD%4K#$VJD1%.E=6LC$V.E>R,#I-LC$Z3T.R-#I(0K(R-38Z
  5862. M6K(P`-L*!`&!($FR,""D(#(Z()<@4ZHUJDFL-RQ!5*PQ-JI$13H@EU.J-JI)
  5863. MK#<L4U6L,3:J4D4`"PL.`9<@4ZHRJDFL-RPT,#`P(*\@,C4U.B"7(%.J,ZI)
  5864. MK#<L-#`P,*TR-38Z(((`+@L8`9<@4ZHR-"PQ-3H@CRLQ-BLV-#I03TM%(%,K
  5865. M,C,L-P!%"RP!H2!!)#J+($$DLB(B(*<@,S`P`'D+-@%&4K)&*$LHQBA!)"DI
  5866. M*:U-.B!4LE:L-SH@0U*R4ZI4JC0Z((L@1E*R6B"G(#4P,`"9"T`!ER!3JC:J
  5867. M5"Q:.B"/($9)3DE32"!$14,O4U53`+D+10&7(%.J-:I4+%HZ((\@1DE.25-(
  5868. M($%45"]214P`UPM*`9<@0U(L.#H@ER!#4BPP.B"/($9)6"!/1D8`^@M4`9<@
  5869. M4ZI4+$92JTA"K+4H1E*M2$(I.B"/(%-%5"!,3P`6#%X!ER!3JC&J5"Q&4JU(
  5870. M0CH@CR!3150@2$D`-`QH`9<@4ZHVJE0L4U8Z((\@4T54($1%0R]355,`4@QM
  5871. M`9<@4ZHUJE0L058Z((\@4T54($%45"]214P`<@QR`9<@0U(L5U:J,3H@@2!)
  5872. MLC$@I"`U,*Q!5#H@@@"'#'<!ER!#4BQ75CH@CR!054Q310"F#'P!BR!0LC$@
  5873. MIR!6LE:J,3H@BR!6LC,@IR!6LC``L`R0`8D@,S`P`-`,]`&+($$DLB*%(B"G
  5874. M($VR,3H@3T.R-#H@B2`S,#``\`S^`8L@022R(H8B(*<@3;(R.B!/0[(S.B")
  5875. M(#,P,``0#0@"BR!!)+(BAR(@IR!-LC0Z($]#LC(Z((D@,S`P`#`-$@*+($$D
  5876. MLB*((B"G($VR.#H@3T.R,3H@B2`S,#``40T<`HL@022R(HDB(*<@5[(P.B!7
  5877. M5K(Q-CH@B2`S,#``<@TF`HL@022R(HHB(*<@5[(Q.B!75K(S,CH@B2`S,#``
  5878. MD@TP`HL@022R(HLB(*<@5[(R.B!75K(V-#H@B3,P,`"S#3H"BR!!)+(BC"(@
  5879. MIR!7LC,Z(%=6LC$R.#H@B3,P,`#/#40"BR!!)+(B("(@IR!0LC&K4#H@B2`S
  5880. M,#``X@U.`HL@022R(I,B(*<@,C`P`.P-6`*)(#,P,`#]#2`#F2)(250@02!+
  5881. M15DB`"`.*@.A($$D.B"+($$DLB(B(*<@.#$P.B"2(($@02!+15D`+`XT`YD@
  5882. (020Z((X`````
  5883. `
  5884. end
  5885.  
  5886.  
  5887.  
  5888. APPENDIX K
  5889.  
  5890.  
  5891. CONVERTING STANDARD
  5892. BASIC PROGRAMS TO
  5893. COMMODORE 64 BASIC
  5894.  
  5895.   If  you  have  programs  written in a BASIC other than Commodore BASIC,
  5896. some  minor  adjustments  may  be  necessary  before  running them on the
  5897. Commodore-64. We've included some hints to make the conversion easier.
  5898.  
  5899.  
  5900. String Dimensions
  5901.  
  5902.   Delete   all  statements  that  are  used  to  declare  the  length  of
  5903. strings.  A  statement  such  as  DIM  A$(I,J), which dimensions a string
  5904. array  for  J  elements of length I, should be converted to the Commodore
  5905. BASIC statement DIM A$(J).
  5906.   Some  BASICs  use  a  comma  or  an ampersand for string concatenation.
  5907. Each  of  these  must  be  changed to a plus sign, which is the Commodore
  5908. BASIC operator for string concatenation.
  5909.   In  Commodore-64  BASIC,  the  MID$,  RIGHT$,  and  LEFT$ functions are
  5910. used  to  take  substrings  of strings. Forms such as A$(I) to access the
  5911. Ith  character  in  A$,  or  A$(I,J)  to  take  a  substring  of  A$ from
  5912. position I to J, must be changed as follows:
  5913.  
  5914. Other BASIC     Commodore 64 BASIC
  5915.  
  5916. A$(I)=X$        A$=LEFT$(A$,I-1)+X$+MID$(A$,I+1)
  5917. A$(I,J)=X$      A$=LEFT$(A$,I-1)+X$+MID$(A$,J+1)
  5918.  
  5919. Multiple Assignments
  5920.  
  5921.   To set B and C equal to zero, some BASICs allow statements of the form:
  5922.  
  5923. 10 LET B=C=0
  5924.  
  5925.   Commodore   64  BASIC  would  interpret  the  second  equal  sign  as a
  5926. logical  operator  and  set  B  =  -1  if  C  =  0. Instead, convert this
  5927. statement to:
  5928.  
  5929. 10 C=0:B=0
  5930.  
  5931. Multiple Statements
  5932.  
  5933.   Some  BASICs  use  a  backslash  to  separate  multiple statements on a
  5934. line. With Commodore 64 BASIC, separate all statements by a colon (:).
  5935.  
  5936. MAT Functions
  5937.  
  5938.   Programs  using  the  MAT  functions  available  on some BASICs must be
  5939. rewritten using FOR...NEXT loops to execute properly.
  5940.  
  5941.  
  5942.  
  5943. APPENDIX L
  5944.  
  5945. ERROR MESSAGES
  5946.  
  5947.  
  5948.   This   appendix   contains  a  complete  list  of  the  error  messages
  5949. generated by the Commodore-64, with a description of causes.
  5950.  
  5951.  
  5952. BAD DATA              String data was received from an open file, but the
  5953.                       program was expecting numeric data.
  5954. BAD SUBSCRIPT         The program was trying to reference an  element  of
  5955.                       an array whose  number  is  outside  of  the  range
  5956.                       specified in the DIM statement.
  5957. BREAK                 Program execution was stopped because you  hit  the
  5958.                       <STOP> key.
  5959. CAN'T CONTINUE        The CONT command will not work,  either because the
  5960.                       program was never RUN,  there has been an error, or
  5961.                       a line has been edited.
  5962. DEVICE NOT PRESENT    The required I/O device was not  available  for  an
  5963.                       OPEN, CLOSE, CMD, PRINT#, INPUT#, or GET#.
  5964. DIVISION BY ZERO      Division by zero is a mathematical oddity  and  not
  5965.                       allowed.
  5966. EXTRA IGNORED         Too many items of data were typed in response to an
  5967.                       INPUT statement. Only the first few items were
  5968.                       accepted.
  5969. FILE NOT FOUND        If you were looking for a file on tape, and END-OF-
  5970.                       TAPE marker was found. If you were looking on disk,
  5971.                       no file with that name exists.
  5972. FILE NOT OPEN         The file specified in a CLOSE, CMD, PRINT#, INPUT#,
  5973.                       or GET#, must first be OPENed.
  5974. FILE OPEN             An attempt was made to open a file using the number
  5975.                       of an already open file.
  5976. FORMULA TOO COMPLEX   The string expression  being  evaluated  should  be
  5977.                       split into at least two parts  for  the  system  to
  5978.                       work with, or a formula has too many parentheses.
  5979. ILLEGAL DIRECT        The  INPUT  statement  can  only  be  used within a
  5980.                       program, and not in direct mode.
  5981. ILLEGAL QUANTITY      A number used as the  argument  of  a  function  or
  5982.                       statement is out of the allowable range.
  5983. LOAD                  There is a problem with the program on tape.
  5984. NEXT WITHOUT FOR      This is caused by either incorrectly nesting  loops
  5985.                       or having a variable name in a NEXT statement  that
  5986.                       doesn't correspond with one in a FOR statement.
  5987. NOT INPUT FILE        An  attempt  was  made  to INPUT or GET data from a
  5988.                       file which was specified to be for output only.
  5989. NOT OUTPUT FILE       An attempt was mode to PRINT data to a  file  which
  5990.                       was specified as input only.
  5991. OUT OF DATA           A READ statement was executed but there is no  data
  5992.                       left unREAD in a DATA statement.
  5993. OUT OF MEMORY         There is no  more  RAM  available  for  program  or
  5994.                       variables.  This  may  also occur when too many FOR
  5995.                       loops have been nested,  or when there are too many
  5996.                       GOSUBs in effect.
  5997. OVERFLOW              The result of a  computation  is  larger  than  the
  5998.                       largest number allowed, which is 1.70141884E+38.
  5999. REDIM'D ARRAY         An array may only be DIMensioned once.  If an array
  6000.                       variable  is  used  before  that array is DIM'd, an
  6001.                       automatic DIM operation is performed on that  array
  6002.                       setting the number of  elements  to  ten,  and  any
  6003.                       subsequent DIMs will cause this error.
  6004. REDO FROM START       Character   data  was  typed  in  during  an  INPUT
  6005.                       statement when numeric data was expected.  Just re-
  6006.                       type  the  entry  so  that  it is correct,  and the
  6007.                       program will continue by itself.
  6008. RETURN WITHOUT GOSUB  A RETURN statement was encountered,  and  no  GOSUB
  6009.                       command has been issued.
  6010. STRING TOO LONG       A string can contain up to 255 characters.
  6011. SYNTAX ERROR          A statement is unrecognizable by the Commodore 64.
  6012.                       A   missing   or   extra   parenthesis,  misspelled
  6013.                       keywords, etc.
  6014. TYPE MISMATCH         This error occurs when a number is used in place of
  6015.                       a string, or vice-versa.
  6016. UNDEF'D FUNCTION      A user defined function was referenced,  but it has
  6017.                       never been defined using the DEF FN statement.
  6018. UNDEF'D STATEMENT     An attempt was made to GOTO or GOSUB or RUN  a line
  6019.                       number that doesn't exist.
  6020. VERIFY                The program on tape or  disk  does  not  match  the
  6021.                       program currently in memory.
  6022. VERIFY                The  program  on  tape  or  disk does not match the
  6023.                       program currently in memory.
  6024.  
  6025.  
  6026.  
  6027. APPENDIX M
  6028.  
  6029. MUSIC NOTE VALUES
  6030.  
  6031.  
  6032.   This  appendix  contains  a  complete  list  of Note#, actual note, and
  6033. the  values  to  be  POKED into the HI FREQ and LOW FREQ registers of the
  6034. sound chip to produce the indicated note.
  6035.  
  6036. +-----------------------------+-----------------------------------------+
  6037. |        MUSICAL NOTE         |             OSCILLATOR FREQ             |
  6038. +-------------+---------------+-------------+-------------+-------------+
  6039. |     NOTE    |    OCTAVE     |   DECIMAL   |      HI     |     LOW     |
  6040. +-------------+---------------+-------------+-------------+-------------+
  6041. |       0     |      C-0      |     268     |       1     |      12     |
  6042. |       1     |      C#-0     |     284     |       1     |      28     |
  6043. |       2     |      D-0      |     301     |       1     |      45     |
  6044. |       3     |      D#-0     |     318     |       1     |      62     |
  6045. |       4     |      E-0      |     337     |       1     |      81     |
  6046. |       5     |      F-0      |     358     |       1     |     102     |
  6047. |       6     |      F#-0     |     379     |       1     |     123     |
  6048. |       7     |      G-0      |     401     |       1     |     145     |
  6049. |       8     |      G#-0     |     425     |       1     |     169     |
  6050. |       9     |      A-0      |     451     |       1     |     195     |
  6051. |      10     |      A#-0     |     477     |       1     |     221     |
  6052. |      11     |      B-0      |     506     |       1     |     250     |
  6053. |      16     |      C-1      |     536     |       2     |      24     |
  6054. |      17     |      C#-1     |     568     |       2     |      56     |
  6055. |      18     |      D-1      |     602     |       2     |      90     |
  6056. |      19     |      D#-1     |     637     |       2     |     125     |
  6057. |      20     |      E-1      |     675     |       2     |     163     |
  6058. |      21     |      F-1      |     716     |       2     |     204     |
  6059. |      22     |      F#-1     |     758     |       2     |     246     |
  6060. |      23     |      G-1      |     803     |       3     |      35     |
  6061. |      24     |      G#-1     |     851     |       3     |      83     |
  6062. |      25     |      A-1      |     902     |       3     |     134     |
  6063. |      26     |      A#-1     |     955     |       3     |     187     |
  6064. |      27     |      B-1      |    1012     |       3     |     244     |
  6065. |      32     |      C-2      |    1072     |       4     |      48     |
  6066. |      33     |      C#-2     |     1136    |       4     |     112     |
  6067. |      34     |      D-2      |     1204    |       4     |     180     |
  6068. |      35     |      D#-2     |     1275    |       4     |     251     |
  6069. |      36     |      E-2      |     1351    |       5     |      71     |
  6070. |      37     |      F-2      |     1432    |       5     |     152     |
  6071. |      38     |      F#-2     |     1517    |       5     |     237     |
  6072. |      39     |      G-2      |     1607    |       6     |      71     |
  6073. |      40     |      G#-2     |     1703    |       6     |     167     |
  6074. |      41     |      A-2      |     1804    |       7     |      12     |
  6075. |      42     |      A#-2     |     1911    |       7     |     119     |
  6076. |      43     |      B-2      |     2025    |       7     |     233     |
  6077. |      48     |      C-3      |     2145    |       8     |      97     |
  6078. |      49     |      C#-3     |     2273    |       8     |     225     |
  6079. |      50     |      D-3      |     2408    |       9     |     104     |
  6080. |      51     |      D#-3     |     2551    |       9     |     247     |
  6081. |      52     |      E-3      |     2703    |      10     |     143     |
  6082. |      53     |      F-3      |     2864    |      11     |      48     |
  6083. |      54     |      F#-3     |     3034    |      11     |     218     |
  6084. |      55     |      G-3      |     3215    |      12     |     143     |
  6085. |      56     |      G#-3     |     3406    |      13     |      78     |
  6086. |      57     |      A-3      |     3608    |      14     |      24     |
  6087. |      58     |      A#-3     |     3823    |      14     |     239     |
  6088. |      59     |      B-3      |     4050    |      15     |     210     |
  6089. |      64     |      C-4      |     4291    |      16     |     195     |
  6090. |      65     |      C#-4     |     4547    |      17     |     195     |
  6091. |      66     |      D-4      |     4817    |      18     |     209     |
  6092. |      67     |      D#-4     |     5103    |      19     |     239     |
  6093. |      68     |      E-4      |     5407    |      21     |      31     |
  6094. |      69     |      F-4      |     5728    |      22     |      96     |
  6095. |      70     |      F#-4     |     6069    |      23     |     181     |
  6096. |      71     |      G-4      |     6430    |      25     |      30     |
  6097. |      72     |      G#-4     |     6812    |      26     |     156     |
  6098. |      73     |      A-4      |     7217    |      28     |      49     |
  6099. |      74     |      A#-4     |     7647    |      29     |     223     |
  6100. |      75     |      B-4      |     8101    |      31     |     165     |
  6101. |      80     |      C-5      |     8583    |      33     |     135     |
  6102. |      81     |      C#-5     |     9094    |      35     |     134     |
  6103. |      82     |      D-5      |     9634    |      37     |     162     |
  6104. |      83     |      D#-5     |    10207    |      39     |     223     |
  6105. |      84     |      E-5      |    10814    |      42     |      62     |
  6106. |      85     |      F-5      |    11457    |      44     |     193     |
  6107. |      86     |      F#-5     |    12139    |      47     |     107     |
  6108. |      87     |      G-5      |    12860    |      50     |      60     |
  6109. |      88     |      G#-5     |    13625    |      53     |      57     |
  6110. |      89     |      A-5      |    14435    |      56     |      99     |
  6111. |      90     |      A#-5     |    15294    |      59     |     190     |
  6112. |      91     |      B-5      |    16203    |      63     |      75     |
  6113. |      96     |      C-6      |    17167    |      67     |      15     |
  6114. |      97     |      C#-6     |    18188    |      71     |      12     |
  6115. |      98     |      D-6      |    19269    |      75     |      69     |
  6116. |      99     |      D#-6     |    20415    |      79     |     191     |
  6117. |     100     |      E-6      |    21629    |      84     |     125     |
  6118. |     101     |      F-6      |    22915    |      89     |     131     |
  6119. |     102     |      F#-6     |    24278    |      94     |     214     |
  6120. |     103     |      G-6      |    25721    |     100     |     121     |
  6121. |     104     |      G#-6     |    27251    |     106     |     115     |
  6122. |     105     |      A-6      |    28871    |     112     |     199     |
  6123. |     106     |      A#-6     |    30588    |     119     |     124     |
  6124. |     107     |      B-6      |    32407    |     126     |     151     |
  6125. |     112     |      C-7      |    34334    |     134     |      30     |
  6126. |     113     |      C#-7     |    36376    |     142     |      24     |
  6127. |     114     |      D-7      |    38539    |     150     |     139     |
  6128. |     115     |      D#-7     |    40830    |     159     |     126     |
  6129. |     116     |      E-7      |    43258    |     168     |     250     |
  6130. |     117     |      F-7      |    45830    |     179     |       6     |
  6131. |     118     |      F#-7     |    48556    |     189     |     172     |
  6132. |     119     |      G-7      |    51443    |     200     |     243     |
  6133. |     120     |      G#-7     |    54502    |     212     |     230     |
  6134. |     121     |      A-7      |    57743    |     225     |     143     |
  6135. |     122     |      A#-7     |    61176    |     238     |     248     |
  6136. |     123     |      B-7      |    64814    |     253     |      46     |
  6137. +-------------+---------------+-------------+-------------+-------------+
  6138.  
  6139.                             FILTER SETTINGS
  6140.              +------------+--------------------------------+
  6141.              |  Location  |            Contents            |
  6142.              +------------+--------------------------------+
  6143.              |    54293   |  Low cutoff frequency (0-7)    |
  6144.              |    54294   |  High cutoff frequency (0-255) |
  6145.              |    54295   |  Resonance (bits 4-7)          |
  6146.              |            |  Filter voice 3 (bit 2)        |
  6147.              |            |  Filter voice 2 (bit 1)        |
  6148.              |            |  Filter voice 1 (bit 0)        |
  6149.              |    54296   |  High pass (bit 6)             |
  6150.              |            |  Bandpass (bit 5)              |
  6151.              |            |  Low pass (bit 4)              |
  6152.              |            |  Volume (bits 0-3)             |
  6153.              +------------+--------------------------------+
  6154.  
  6155.  
  6156.  
  6157. APPENDIX N
  6158.  
  6159. BIBLIOGRAPHY
  6160.  
  6161.  
  6162. Addison-Wesley          "BASIC and the Personal Computer", Dwyer and
  6163.                         Critchfield
  6164.  
  6165. Compute                 "Compute's First Book of PET/CBM"
  6166.  
  6167. Cowbay Computing        "Feed Me, I'm Your PET Computer", Carol Alexander
  6168.  
  6169.                         "Looking Good with Your PET", Carol Alexander
  6170.  
  6171.                         "Teacher's PET-Plans, Quizzes, and Answers"
  6172.  
  6173. Creative Computing      "Getting Acquainted With Your VIC 20",
  6174.                         T. Hartnell
  6175.  
  6176. Dilithium Press         "BASIC Basic-English Dictionary for the PET",
  6177.                         Lorry Noonan
  6178.  
  6179.                         "PET BASIC", Tom Rugg and Phil Feldman
  6180.  
  6181. Faulk Baker Associates  "MOS Programming Manual", MOS Technology
  6182.  
  6183. Hoyden Book Co.         "BASIC From the Ground Up", David E. Simon
  6184.  
  6185.                         "I Speak BASIC to My PET", Aubrey Jones, Jr.
  6186.  
  6187.                         "Library of PET Subroutines',', Nick Hampshire
  6188.  
  6189.                         "PET Graphics", Nick Hampshire
  6190.  
  6191.                         "BASIC Conversions Handbook, Apple, TRS-80, and
  6192.                         PET", David A. Brain, Phillip R. Oviatt,
  6193.                         Paul J. Paquin, and Chandler P. Stone
  6194.  
  6195. Howard W. Sams          "The Howard W. Sams Crash Course in
  6196.                         Microcomputers", Louis E. Frenzel, Jr.
  6197.  
  6198.                         "Mostly BASIC: Applications for Your PET",
  6199.                         Howard Berenbon
  6200.  
  6201.                         "PET Interfacing", James M. Downey and Steven
  6202.                         M. Rogers
  6203.  
  6204.                         "VIC 20 Programmer's Reference Guide", A. Finkel,
  6205.                         P. Higginbottom, N. Harris, and M. Tomczyk
  6206.  
  6207. Little, Brown & Co.     "Computer Games for Businesses, Schools, and
  6208.                         Homes", J. Victor Nagigian, and William S. Hodges
  6209.  
  6210.                         "The Computer Tutor: Learning Activities for
  6211.                         Homes and Schools", Gary W. Orwig, University of
  6212.                         Central Florida, and William S. Hodges
  6213.  
  6214. McGraw-Hill             "Hands-On BASIC With a PET", Herbert D. Peckman
  6215.  
  6216.                         "Home and Office Use of VisiCalc", D. Castlewitz,
  6217.                         and L. Chisauki
  6218.  
  6219. Osborne/McGraw-Hill     "PET/CBM Personal Computer Guide", Carroll
  6220.                         S. Donahue
  6221.  
  6222.                         "PET Fun and Games", R. Jeffries and G. Fisher
  6223.  
  6224.                         "PET and the IEEE", A. Osborne and C. Donahue
  6225.  
  6226.                         "Some Common BASIC Programs for the PET",
  6227.                         L. Poole, M. Borchers, and C. Donahue
  6228.  
  6229.                         "Osborne CP/M User Guide", Thorn Hogan
  6230.  
  6231.                         "CBM Professional Computer Guide"
  6232.  
  6233.                         "The PET Personal Guide"
  6234.  
  6235.                         "The 8086 Book", Russell Rector and George Alexy
  6236.  
  6237. P. C. Publications      "Beginning Self-Teaching Computer Lessons"
  6238.  
  6239. Prentice-Hall           "The PET Personal Computer for Beginners",
  6240.                         S. Dunn and V. Morgan
  6241.  
  6242. Reston Publishing Co.   "PET and the IEEE 488 Bus (GPIB)", Eugene
  6243.                         Fisher and C. W. Jensen
  6244.  
  6245.                         "PET BASIC-Training Your PET Computer",
  6246.                         Roman Zamora, Wm. F. Carrie, and B. Allbrecht
  6247.  
  6248.                         "PET Games and Recreation", M. Ogelsby, L.
  6249.                         Lindsey, and D. Kunkin
  6250.  
  6251.                         "PET BASIC", Richard Huskell
  6252.  
  6253.                         "VIC Games and Recreation"
  6254.  
  6255. Telmas Courseware       "BASIC and the Personal Computer", T. A. Dwyer,
  6256. Ratings                 and M. Critchfield
  6257.  
  6258. Total Information       "Understanding Your PET/CBM, Vol. 1, BASIC
  6259. Services                Programming"
  6260.  
  6261.                         "Understanding Your VIC", David Schultz
  6262.  
  6263.  
  6264.   Commodore  Magazines  provide  you with the most up-to-date information
  6265. for  your  Commodore 64.  Two  of  the most popular publications that you
  6266. should seriously consider subscribing to are:
  6267.  
  6268.   COMMODORE -- The  Microcomputer  Magazine is published bimonthly and is
  6269. available  by  subscription  ($15.00 per year, U.S., and $25.00 per year,
  6270. worldwide).
  6271.  
  6272.   POWER/PLAY -- The Home Computer Magazine is, published quarterly and is
  6273. available  by subscription  ($10.00 per year,  U.S.,  and $15.00 per year
  6274. worldwide).
  6275.  
  6276.  
  6277.  
  6278. APPENDIX O
  6279.  
  6280. SPRITE REGISTER MAP
  6281.  
  6282.  
  6283. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6284. |Register#|     |     |     |     |     |     |     |     |             |
  6285. | Dec Hex | DB7 | DB6 | DB5 | DB4 | DB3 | DB2 | DB1 | DB0 |             |
  6286. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6287. |  0   0  |S0X7 |     |     |     |     |     |     |S0X0 |SPRITE 0 X   |
  6288. |         |     |     |     |     |     |     |     |     |Component    |
  6289. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6290. |  1   1  |S0Y7 |     |     |     |     |     |     |S0Y0 |SPRITE 0 Y   |
  6291. |         |     |     |     |     |     |     |     |     |Component    |
  6292. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6293. |  2   2  |S1X7 |     |     |     |     |     |     |S1X0 |SPRITE 1 X   |
  6294. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6295. |  3   3  |S1Y7 |     |     |     |     |     |     |S1Y0 |SPRITE 1 Y   |
  6296. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6297. |  4   4  |S2X7 |     |     |     |     |     |     |S2X0 |SPRITE 2 X   |
  6298. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6299. |  5   5  |S2Y7 |     |     |     |     |     |     |S2Y0 |SPRITE 2 Y   |
  6300. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6301. |  6   6  |S3X7 |     |     |     |     |     |     |S3X0 |SPRITE 3 X   |
  6302. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6303. |  7   7  |S3Y7 |     |     |     |     |     |     |S3Y0 |SPRITE 3 Y   |
  6304. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6305. |  8   8  |S4X7 |     |     |     |     |     |     |S4X0 |SPRITE 4 X   |
  6306. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6307. |  9   9  |S4Y7 |     |     |     |     |     |     |S4Y0 |SPRITE 4 Y   |
  6308. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6309. | 10   A  |S5X7 |     |     |     |     |     |     |S5X0 |SPRITE 5 X   |
  6310. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6311. | 11   B  |S5Y7 |     |     |     |     |     |     |S5Y0 |SPRITE 5 Y   |
  6312. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6313. | 12   C  |S6X7 |     |     |     |     |     |     |S6X0 |SPRITE 6 X   |
  6314. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6315. | 13   D  |S6Y7 |     |     |     |     |     |     |S6Y0 |SPRITE 6 Y   |
  6316. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6317. | 14   E  |S7X7 |     |     |     |     |     |     |S7X0 |SPRITE 7 X   |
  6318. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6319. | 15   F  |S7Y7 |     |     |     |     |     |     |S7Y0 |SPRITE 7 Y   |
  6320. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6321. | 16  10  |S7X8 |S6X8 |S5X8 |S4X8 |S3X8 |S2X8 |S1X8 |S0X8 |MSB of X     |
  6322. |         |     |     |     |     |     |     |     |     |COORD.       |
  6323. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6324. | 17  11  | RC8 | ECM | BMM |BLNK |RSEL |YSCL2|YSCL1|YSCL0|Y SCROLL     |
  6325. |         |     |     |     |     |     |     |     |     |Mode         |
  6326. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6327. | 18  12  | RC7 | RC6 | RC5 | RC4 | RC3 | RC2 | RC1 | RC0 |RASTER       |
  6328. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6329. | 19  13  |LPX7 |     |     |     |     |     |     |LPX0 |LIGHT PEN X  |
  6330. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6331. | 20  14  |LPY7 |     |     |     |     |     |     |LPY0 |LIGHT PEN Y  |
  6332. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6333. | 21  15  | SE7 |     |     |     |     |     |     | SE0 |SPRITE       |
  6334. |         |     |     |     |     |     |     |     |     |ENABLE       |
  6335. |         |     |     |     |     |     |     |     |     |(ON/OFF)     |
  6336. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6337. | 22  16  |N.C. |N.C. | RST | MCM |CSEL |XSCL2|XSCL1|XSCL0|X SCROLL     |
  6338. |         |     |     |     |     |     |     |     |     |MODE         |
  6339. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6340. | 23  17  |SEX7 |     |     |     |     |     |     |SEX0 |SPRITE       |
  6341. |         |     |     |     |     |     |     |     |     |EXPAND Y     |
  6342. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6343. | 24  18  |VS13 |VS12 |VS11 |VS10 |CB13 |CB12 |CB11 |N.C. |SCREEN       |
  6344. |         |     |     |     |     |     |     |     |     |Character    |
  6345. |         |     |     |     |     |     |     |     |     |Memory       |
  6346. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6347. | 25  19  |IRQ  |N.C. |N.C. |N.C. |LPIRQ|ISSC |ISBC |RIRIQ|Interrupt    |
  6348. |         |     |     |     |     |     |     |     |     |Request's    |
  6349. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6350. | 26  1A  |N.C. |N.C. |N.C. |N.C. |MLPI |MISSC|MISBC|MRIRQ|Interrupt    |
  6351. |         |     |     |     |     |     |     |     |     |Request      |
  6352. |         |     |     |     |     |     |     |     |     |MASKS        |
  6353. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6354. | 27  1B  |BSP7 |     |     |     |     |     |     |BSP0 |Background   |
  6355. |         |     |     |     |     |     |     |     |     |Sprite       |
  6356. |         |     |     |     |     |     |     |     |     |PRIORITY     |
  6357. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6358. | 28  1C  |SCM7 |     |     |     |     |     |     |SCM0 |MULTICOLOR   |
  6359. |         |     |     |     |     |     |     |     |     |SPRITE       |
  6360. |         |     |     |     |     |     |     |     |     |SELECT       |
  6361. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6362. | 29  1D  |SEXX7|     |     |     |     |     |     |SEXX0|SPRITE       |
  6363. |         |     |     |     |     |     |     |     |     |EXPAND X     |
  6364. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6365. | 30  1E  |SSC7 |     |     |     |     |     |     |SSC0 |Sprite-Sprite|
  6366. |         |     |     |     |     |     |     |     |     |COLLISION    |
  6367. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6368. | 31  1F  |SBC7 |     |     |     |     |     |     |SBC0 |Sprite-      |
  6369. |         |     |     |     |     |     |     |     |     |Background   |
  6370. |         |     |     |     |     |     |     |     |     |COLLISION    |
  6371. +---------+-----+-----+-----+-----+-----+-----+-----+-----+-------------+
  6372.  
  6373.            COLOR CODES
  6374.             DEC  HEX    COLOR
  6375. +---------+-----------------------+-----+-----+-----+-----+-------------+
  6376. | 32  20  |  0    0     BLACK     |EXT 1|     |     |     |EXTERIOR COL |
  6377. +---------+-----------------------+-----+-----+-----+-----+-------------+
  6378. | 33  21  |  1    1     WHITE     |BKGD0|     |     |     |BACKGROUND 0 |
  6379. +---------+-----------------------+-----+-----+-----+-----+-------------+
  6380. | 34  22  |  2    2     RED       |BKGD1|     |     |     |BACKGROUND 1 |
  6381. +---------+-----------------------+-----+-----+-----+-----+-------------+
  6382. | 35  23  |  3    3     CYAN      |BKGD2|     |     |     |BACKGROUND 2 |
  6383. +---------+-----------------------+-----+-----+-----+-----+-------------+
  6384. | 36  24  |  4    4     PURPLE    |BKGD3|     |     |     |BACKGROUND 3 |
  6385. +---------+-----------------------+-----+-----+-----+-----+-------------+
  6386. | 37  25  |  5    5     GREEN     |SMC 0|     |     |     |   SPRITE    |
  6387. |         |                       |     |     |     |     |MULTICOLOR 0 |
  6388. +---------+-----------------------+-----+-----+-----+-----+-------------+
  6389. | 38  26  |  6    6     BLUE      |SMC 1|     |     |     |   SPRITE    |
  6390. |         |                       |     |     |     |     |MULTICOLOR 1 |
  6391. +---------+-----------------------+-----+-----+-----+-----+-------------+
  6392. | 39  27  |  7    7     YELLOW    |S0COL|     |     |     |SPRITE 0 COL |
  6393. +---------+-----------------------+-----+-----+-----+-----+-------------+
  6394. | 40  28  |  8    8     ORANGE    |S1COL|     |     |     |SPRITE 1 COL |
  6395. +---------+-----------------------+-----+-----+-----+-----+-------------+
  6396. | 41  29  |  9    9     BROWN     |S2COL|     |     |     |SPRITE 2 COL |
  6397. +---------+-----------------------+-----+-----+-----+-----+-------------+
  6398. | 42  2A  | 10    A     LT RED    |S3COL|     |     |     |SPRITE 3 COL |
  6399. +---------+-----------------------+-----+-----+-----+-----+-------------+
  6400. | 43  2B  | 11    B     GRAY 1    |S4COL|     |     |     |SPRITE 4 COL |
  6401. +---------+-----------------------+-----+-----+-----+-----+-------------+
  6402. | 44  2C  | 12    C     GRAY 2    |S5COL|     |     |     |SPRITE 5 COL |
  6403. +---------+-----------------------+-----+-----+-----+-----+-------------+
  6404. | 45  2D  | 13    D     LT GREEN  |S6COL|     |     |     |SPRITE 6 COL |
  6405. +---------+-----------------------+-----+-----+-----+-----+-------------+
  6406. | 46  2E  | 14    E     LT BLUE   |S7COL|     |     |     |SPRITE 7 COL |
  6407. +---------+-----------------------+-----+-----+-----+-----+-------------+
  6408. |         | 15    F     GRAY 3    |     |     |     |     |             |
  6409. +---------+-----------------------+-----+-----+-----+-----+-------------+
  6410.  
  6411. LEGEND:
  6412. ONLY COLORS 0-7 MAY BE USED IN MULTICOLOR CHARACTER MODE.
  6413.  
  6414.  
  6415.  
  6416. APPENDIX P
  6417.  
  6418. COMMODORE 64 SOUND CONTROL SETTINGS
  6419.  
  6420.  
  6421.   This  handy  table  gives  you  the key numbers you need to use in your
  6422. sound  programs,  according  to  which of the Commodore 64's 3 voices you
  6423. want to use. To set or adjust a sound control in your BASIC program, just
  6424. POKE  the  number  from  the second column, followed by a comma (,) and a
  6425. number  from  the  chart ... like this: POKE 54276,17 (Selects a Triangle
  6426. Waveform for VOICE 1).
  6427.   Remember  that  you  must set the VOLUME before you can generate sound.
  6428. POKE  54296  followed  by a number from 0 to 15 sets the volume for all 3
  6429. voices.
  6430.   It takes 2 separate POKEs to generate each musical note ... for example
  6431. POKE 54273,34: POKE 54272,75 designates low C in the sample scale bellow.
  6432.   Also  ...  you aren't limited to the numbers shown in the tables. If 34
  6433. doesn't sound "right" for a low C, try 35. To provide a higher SUSTAIN or
  6434. ATTACK  rate than those shown,  add two or more SUSTAIN numbers together.
  6435. (Examples:  POKE  54277,96  combines  two  attack rates (32 and 64) for a
  6436. combined  higher  attack  rate  ...  but ... POKE 54277,20 provides a low
  6437. attack rate (16) and a medium decay rate (4).
  6438.  
  6439.  
  6440. +----------------------------------------------------------------------------+
  6441. |SETTING VOLUME -- SAME FOR ALL 3 VOICES                                     |
  6442. +--------------+---------+---------------------------------------------------+
  6443. |VOLUME CONTROL|POKE54296| Settings from 0 (off) to 15 (loudest)             |
  6444. +--------------+---------+---------------------------------------------------+
  6445.                               VOICE NUMBER 1
  6446. +--------------+---------+---------------------------------------------------+
  6447. |TO CONTROL    |POKE THIS|         FOLLOWED BY ONE OF THESE NUMBERS          |
  6448. |THIS SETTING: |NUMBER:  | (0 to 15 ... or ... 0 to 255 depending on range)  |
  6449. +--------------+---------+---------------------------------------------------+
  6450. |TO PLAY A NOTE|      C  | C#| D | D#| E | F | F#| G | G#| A | A#| B | C | C#|
  6451. |HIGH FREQUENCY|54273 34 | 36| 38| 40| 43| 45| 48| 51| 54| 57| 61| 64| 68| 72|
  6452. |LOW FREQUENCY |54272 75 | 85|126|200| 52|198|127| 97|111|172|126|188|149|169|
  6453. +--------------+---------+------------+------------+------------+------------+
  6454. |WAVEFORM      |  POKE   |  TRIANGLE  |  SAWTOOTH  |   PULSE    |   NOISE    |
  6455. |              |  54276  |     17     |     33     |     65     |    129     |
  6456. +--------------+---------+------------+------------+------------+------------+
  6457. |PULSE RATE (Pulse Waveform)                                                 |
  6458. |HI POLSE      |  54275  |   A value of 0 to 15  (for Pulse waveform only)   |
  6459. |LO POLSE      |  54274  |   A value of 0 to 255 (for Pulse waveform only)   |
  6460. +--------------+---------+------+------+------+------+-----+-----+-----+-----+
  6461. |ATTACK/       |  POKE   | ATK4 | ATK3 | ATK2 | ATK1 | DEC4| DEC3| DEC2| DEC1|
  6462. |       DECAY  |  54277  | 128  |  64  |  32  |  16  |  8  |  4  |  2  |  1  |
  6463. +--------------+---------+------+------+------+------+-----+-----+-----+-----+
  6464. |SUSTAIN/      |  POKE   | SUS4 | SUS3 | SUS2 | SUS1 | REL4| REL3| REL2| REL1|
  6465. |       RELEASE|  54278  | 128  |  64  |  32  |  16  |  8  |  4  |  2  |  1  |
  6466. +--------------+---------+------+------+------+------+-----+-----+-----+-----+
  6467.                               VOICE NUMBER 2
  6468. +--------------+---------+---------------------------------------------------+
  6469. |TO CONTROL    |POKE THIS|         FOLLOWED BY ONE OF THESE NUMBERS          |
  6470. |THIS SETTING: |NUMBER:  | (0 to 15 ... or ... 0 to 255 depending on range)  |
  6471. +--------------+---------+---------------------------------------------------+
  6472. |TO PLAY A NOTE|      C  | C#| D | D#| E | F | F#| G | G#| A | A#| B | C | C#|
  6473. |HIGH FREQUENCY|54280 34 | 36| 38| 40| 43| 45| 48| 51| 54| 57| 61| 64| 68| 72|
  6474. |LOW FREQUENCY |54279 75 | 85|126|200| 52|198|127| 97|111|172|126|188|149|169|
  6475. +--------------+---------+------------+------------+------------+------------+
  6476. |WAVEFORM      |  POKE   |  TRIANGLE  |  SAWTOOTH  |   PULSE    |   NOISE    |
  6477. |              |  54283  |     17     |     33     |     65     |    129     |
  6478. +--------------+---------+------------+------------+------------+------------+
  6479. |PULSE RATE (Pulse Waveform)                                                 |
  6480. |HI POLSE      |  54282  |   A value of 0 to 15  (for Pulse waveform only)   |
  6481. |LO POLSE      |  54281  |   A value of 0 to 255 (for Pulse waveform only)   |
  6482. +--------------+---------+------+------+------+------+-----+-----+-----+-----+
  6483. |ATTACK/       |  POKE   | ATK4 | ATK3 | ATK2 | ATK1 | DEC4| DEC3| DEC2| DEC1|
  6484. |       DECAY  |  54284  | 128  |  64  |  32  |  16  |  8  |  4  |  2  |  1  |
  6485. +--------------+---------+------+------+------+------+-----+-----+-----+-----+
  6486. |SUSTAIN/      |  POKE   | SUS4 | SUS3 | SUS2 | SUS1 | REL4| REL3| REL2| REL1|
  6487. |       RELEASE|  54285  | 128  |  64  |  32  |  16  |  8  |  4  |  2  |  1  |
  6488. +--------------+---------+------+------+------+------+-----+-----+-----+-----+
  6489.                               VOICE NUMBER 3
  6490. +--------------+---------+---------------------------------------------------+
  6491. |TO CONTROL    |POKE THIS|         FOLLOWED BY ONE OF THESE NUMBERS          |
  6492. |THIS SETTING: |NUMBER:  | (0 to 15 ... or ... 0 to 255 depending on range)  |
  6493. +--------------+---------+---------------------------------------------------+
  6494. |TO PLAY A NOTE|      C  | C#| D | D#| E | F | F#| G | G#| A | A#| B | C | C#|
  6495. |HIGH FREQUENCY|54287 34 | 36| 38| 40| 43| 45| 48| 51| 54| 57| 61| 64| 68| 72|
  6496. |LOW FREQUENCY |54286 75 | 85|126|200| 52|198|127| 97|111|172|126|188|149|169|
  6497. +--------------+---------+------------+------------+------------+------------+
  6498. |WAVEFORM      |  POKE   |  TRIANGLE  |  SAWTOOTH  |   PULSE    |   NOISE    |
  6499. |              |  54290  |     17     |     33     |     65     |    129     |
  6500. +--------------+---------+------------+------------+------------+------------+
  6501. |PULSE RATE (Pulse Waveform)                                                 |
  6502. |HI POLSE      |  54289  |   A value of 0 to 15  (for Pulse waveform only)   |
  6503. |LO POLSE      |  54288  |   A value of 0 to 255 (for Pulse waveform only)   |
  6504. +--------------+---------+------+------+------+------+-----+-----+-----+-----+
  6505. |ATTACK/       |  POKE   | ATK4 | ATK3 | ATK2 | ATK1 | DEC4| DEC3| DEC2| DEC1|
  6506. |       DECAY  |  54291  | 128  |  64  |  32  |  16  |  8  |  4  |  2  |  1  |
  6507. +--------------+---------+------+------+------+------+-----+-----+-----+-----+
  6508. |SUSTAIN/      |  POKE   | SUS4 | SUS3 | SUS2 | SUS1 | REL4| REL3| REL2| REL1|
  6509. |       RELEASE|  54292  | 128  |  64  |  32  |  16  |  8  |  4  |  2  |  1  |
  6510. +--------------+---------+------+------+------+------+-----+-----+-----+-----+
  6511.  
  6512.  
  6513. TRY THESE SETTINGS TO SIMULATE DIFFERENT INSTRUMENTS
  6514.  
  6515. +------------+----------+--------------+---------------+----------------+
  6516. | Instrument | Waveform | Attack/Decay |Sustain/Release| Pulse Rate     |
  6517. +------------+----------+--------------+---------------+----------------+
  6518. | Piano      | Pulse    |       9      |        0      | Hi-0, Lo-255   |
  6519. | Flute      | Triangle |      96      |        0      | Not applicable |
  6520. | Harpsichord| Sawtooth |       9      |        0      | Not applicable |
  6521. | Xylophone  | Triangle |       9      |        0      | Not applicable |
  6522. | Organ      | Triangle |       0      |      240      | Not applicable |
  6523. | Colliape   | Triangle |       0      |      240      | Not applicable |
  6524. | Accordian  | Triangle |     102      |        0      | Not applicable |
  6525. | Trumpet    | Sawtooth |      96      |        0      | Not applicable |
  6526. +------------+----------+--------------+---------------+----------------+
  6527.  
  6528. MEANINGS OF SOUND TERMS
  6529.  
  6530. ADSR     -- Attack/Decay/Sustain/Release
  6531. Attack   -- Rate sound rises to peak volume
  6532. Decay    -- Rate sound falls from peak volume to Sustain level
  6533. Sustain  -- Prolong note at certain volume
  6534. Release  -- Rate at which volume falls from Sustain level
  6535. Waveform -- "Shape" of sound wave
  6536. Pulse    -- Tone quality of Pulse Waveform
  6537.  
  6538. NOTE: Attack/Decay and Sustain/Release settings should always be POKEd in
  6539. your program BEFORE the Waveform is POKEd.
  6540.  
  6541.  
  6542.  
  6543. INDEX
  6544.  
  6545. A
  6546.  Abbreviations, BASIC commands, D
  6547.  Accesories, INTRODUCTION, A
  6548.  Addition, 2.4-2.5, C
  6549.  AND operator, 5.4, C
  6550.  Animation, 4.1, 5.6, 6.2, E, G
  6551.  Arithmetic, Operators, 2.4-2.5, C
  6552.  Arithmetic, Formulas, 2.4-2.5, C, H
  6553.  Arrays, 8.3-8.6
  6554.  ASC function, 4.8, C, F
  6555.  ASCII character codes, F
  6556.  
  6557. B
  6558.  BASIC
  6559.    abbreviations, D
  6560.    commands, C
  6561.    numeric functions, C
  6562.    operators, 2.4, C
  6563.    other functions, C
  6564.    statements, C
  6565.    string functions, C
  6566.    variables, 3.3, C
  6567.  Bibliography, N
  6568.  Binary arithmetic, 6.3-6.4
  6569.  Bit, 6.3-6.4
  6570.  Business aids, A
  6571.  Byte, 6.4
  6572.  
  6573. C
  6574.  Calculations, 2.4-2.6
  6575.  Cassette tape recorder (audio), 1.1, 2.3
  6576.  Cassette tape recorder (video), 1.3
  6577.  Cassette port, 1.1
  6578.  CHR$ function, 3.3, 4.3, 4.8, 5.3, C, F, K
  6579.  CLR statement, C
  6580.  CLR/HOME key, 2.1, 3.1, 4.2
  6581.  Clock, C
  6582.  CLOSE statement, B, C
  6583.  Color
  6584.    adjustment, 1.5
  6585.    CHR$ codes, 5.3
  6586.    keys, 5.1-5.2
  6587.    memory map, 5.5, G
  6588.    PEEKS and POKES, 5.4
  6589.    screen and border, 5.4-5.5, G
  6590.  Commands, BASIC, C
  6591.  Commodore key, (see graphic keys)
  6592.  Connections
  6593.    optional, 1.3
  6594.    rear, 1.1
  6595.    side panel, 1.1
  6596.    TV/Monitor, 1.2
  6597.  CONT command, C
  6598.  ConTRoL key, 1.5, 2.1
  6599.  COSine function, C
  6600.  CuRSoR keys, 1.4, 2.1, 3.2
  6601.  Correcting errors, 3.2
  6602.  Cursor, 1.4
  6603.  
  6604. D
  6605.  DATASSETTE recorder, (see cassette tape recorder, audio)
  6606.  Data, loading and saving (disk), 2.3, C
  6607.  Data, loading and saving (tape), 2.3, C
  6608.  DATA statement, 6.2, 6.3, 7.4, 7.6, 8.1, C
  6609.  DEFine statement, C
  6610.  Delay loop, 5.4, 5.8
  6611.  DELete key, 2.1
  6612.  DIMension statement, 8.4, C
  6613.  Division, 2.4-2.5, C
  6614.  Duration, (see FOR ... NEXT)
  6615.  
  6616. E
  6617.  Editing program, 2.1, 3.2
  6618.  END statement, 3.4, C
  6619.  Equal, not-equal-to, signs, 2.4-2.5, 3.4, C
  6620.  Equations, 3.4, C
  6621.  Error messages, 2.4, L
  6622.  Expansion port, I
  6623.  EXPonent function, C
  6624.  Exponentiation, 2.4-2.5, C
  6625.  
  6626. F
  6627.  Files, (tape), 2.3, B, C
  6628.  Files, (disk), 2.3, C
  6629.  FOR statement, 3.5, C
  6630.  FRE function, C
  6631.  Functions, C
  6632.  
  6633. G
  6634.  Game controls and ports, 1.1, I
  6635.  GET statement, 4.4, C
  6636.  GET# statement, C
  6637.  Getting started, 2.1-2.6
  6638.  GOSUB statement, C
  6639.  GOTO (GO TO) statement, 3.1, C
  6640.  Graphic keys, 2.1, 5.1-5.2, 5.4, E
  6641.  Graphic symbols, (see graphic keys)
  6642.  Greater than, 3.4, C
  6643.  
  6644. H
  6645.  Hyperbolic functions, H
  6646.  
  6647. I
  6648.  IEEE-488 Interface, A
  6649.  IF ... THEN statement, 3.4, C
  6650.  INPUT statement, 4.3, C
  6651.  INPUT# statement, C
  6652.  INSerT key, 2.1, 3.2
  6653.  INTeger function, 4.5, C
  6654.  I/O pinouts, I
  6655.  I/O ports, 1.1-1.3
  6656.  
  6657. J
  6658.  Joysticks, 1.1, I
  6659.  
  6660. K
  6661.  Keyboard, 2.1-2.2
  6662.  
  6663. L
  6664.  LEFT$ function, C
  6665.  LENgth function, 6.4, C
  6666.  Less than, 3.4, C
  6667.  LET statement, C
  6668.  LIST command, 3.1-3.2, C
  6669.  LOAD command, 2.3, C
  6670.  LOADing programs from tape, 2.3, C
  6671.  LOADing programs from disk, 2.3, C
  6672.  LOGarithm, C
  6673.  Loops, 3.5, 4.2-4.3
  6674.  Lower Case characters, 2.1
  6675.  
  6676. M
  6677.  Mathematics
  6678.    formulas, 2.4-2.5
  6679.    function table, H
  6680.    symbols, 2.4-2.5, 3.4
  6681.  Memory maps, 5.5, G, O, P
  6682.  MID$ function, 6.4, C
  6683.  Modulator, RF, 1.2-1.3
  6684.  Multiplication, 2.4-2.5, C
  6685.  Music, 7.1-7.8
  6686.  
  6687. N
  6688.  Names
  6689.    program, 2.3, C
  6690.    variable, 3.3, C
  6691.  NEW command, 3.1, C
  6692.  NEXT statement, 3.5, C
  6693.  NOT operator, C
  6694.  Numeric variables, 3.3
  6695.  
  6696. O
  6697.  ON statement, C
  6698.  OPEN statement, C
  6699.  Operators
  6700.    arithmetic, 2.4, C
  6701.    logical, C
  6702.    relational, 3.4, C
  6703.  
  6704. P
  6705.  Parentheses, 2.5
  6706.  PEEK function, 5.4, 5.6
  6707.  Peripherals, 1.1-1.3
  6708.  POKE statement, 5.4
  6709.  Ports, I/O, 1.1, I
  6710.  POS function, C
  6711.  PRINT statement, 2.4, C
  6712.  PRINT# statement, C
  6713.  Precedence, 2.5
  6714.  Programs
  6715.    editing, 2.1, 3.2
  6716.    line numbering, 3.1
  6717.    loading/saving (tape), 2.3, C
  6718.    loading/saving (disk), 2.3, C
  6719.  Prompt, 4.3
  6720.  
  6721. Q
  6722.  Quotation marks, 2.4
  6723.  
  6724. R
  6725.  RaNDom function, 4.5-4.8, C
  6726.  Random numbers, 4.5-4.8
  6727.  READ statement, 8.1-8.2, C
  6728.  Reading from tape, B
  6729.  REMark statement, 4.2, C
  6730.  Reserved words, (see Commands, BASIC)
  6731.  RESTORE key, 2.1-2.2
  6732.  RESTORE statement, 8.1, C
  6733.  RETURN key, 2.1-2.2
  6734.  RETURN statement, C
  6735.  RIGHT$ function, C
  6736.  RUN command, C
  6737.  RUN/STOP key, 2.1, 3.1
  6738.  
  6739. S
  6740.  SAVE command, 2.3, C
  6741.  Saving programs (tape), 2.3, C
  6742.  Saving programs (disk), 2.3, C
  6743.  Screen memory maps, 5.5, G
  6744.  SGN function, C
  6745.  SHIFT key, 2.1-2.2
  6746.  SINe function, C
  6747.  Sound effects, 7.7-7.8
  6748.  SPC function, 8.6, C
  6749.  SPRITE EDITOR, INTRODUCTION
  6750.  SPRITE graphics, 6.1-6.3
  6751.  SQuaRe function, C
  6752.  STOP command, C
  6753.  STOP key, 2.1
  6754.  String variables, 3.3
  6755.  STR$ function, C
  6756.  Subscripted variables, 8.3
  6757.  Subtraction, 2.4-2.5, C
  6758.  SYNTAX ERROR, 2.4
  6759.  SYS statement, C
  6760.  
  6761. T
  6762.  TAB function, C
  6763.  TAN function, C
  6764.  TI variable, C
  6765.  TI$ variable, C
  6766.  Time clock, C
  6767.  TV connections, 1.2-1.3
  6768.  
  6769. U
  6770.  Upper/Lower Case mode, 2.1, E
  6771.  USR function, C
  6772.  User defined function, (see DEF)
  6773.  
  6774. V
  6775.  VALue function, 6.4, C
  6776.  Variables
  6777.    array, 8.3-8.6, C
  6778.    dimensions, 8.4-8.6, C
  6779.    floating point, 3.3, C
  6780.    integer, 3.3, C
  6781.    numeric, 3.3, 4.3, C
  6782.    string ($), 3.3, 4.3, C
  6783.  VERIFY command, C
  6784.  Voice, 7.1-7.8, P
  6785.  
  6786. W
  6787.  WAIT command, C
  6788.  Writing to tape, B
  6789.  
  6790. Z,
  6791.  Z-80, INTRODUCTION, A
  6792.  
  6793.  
  6794.  
  6795. Commodore  hopes  you've enjoyed the COMMODORE 64 USER'S GUIDE.  Although
  6796. this  manual  contains  some  programming information and tips, it is NOT
  6797. intended to be a Programmer's Reference Manual.  For those of you who are
  6798. advanced  programmers  and computer hobbyists Commodore suggests that you
  6799. consider  purchasing  COMMODORE 64 PROGRAMMER'S REFERENCE GUIDE available
  6800. through your local Commodore dealer.
  6801.  
  6802.  
  6803. In addition updates and corrections as well as programming hints and tips
  6804. are available in the COMMODORE and POWER PLAY magazines, on the COMMODORE
  6805. database  of  the  COMPUSERVE  INFORMATION  NETWORK,  accessed  through a
  6806. VICMODEM.
  6807.  
  6808.  
  6809.  
  6810. COMMODORE 64 QUICK REFERENCE CARD
  6811.  
  6812.  
  6813. SIMPLE VARIABLES
  6814.  
  6815. TYPE     NAME    RANGE
  6816. Real     XY      +/-1.70141183E+38
  6817.                  +/-2.93873588E-39
  6818. Integer  XY%     +32767...-32768
  6819. String   XY$     0 to 255 characters
  6820.  
  6821. X is a letter (A-Z). Y is a letter or number (0-9). Variable names can be
  6822. more than 2 characters, but only the first two are recognized.
  6823.  
  6824.  
  6825. ARRAY VARIABLES
  6826.  
  6827. TYPE                 NAME
  6828. Single Dimension     XY(5)
  6829. Two-Dimension        XY(5,5)
  6830. Three-Dimension      XY(5,5,5)
  6831.  
  6832. Arrays  of  up  to  eleven  elements  (subscripts 0-10) can be used where
  6833. needed.  Arrays  with  more  than eleven elements need to be DIMensioned.
  6834.  
  6835.  
  6836. ALGEBRAIC OPERATIONS
  6837.  
  6838. =   Assigns value to variable
  6839. -   Negation
  6840. ^   Exponentiation
  6841. *   Multiplication
  6842. /   Division
  6843. +   Addition
  6844. -   Subtraction
  6845.  
  6846.  
  6847. RELATION AND LOGICAL OPERATORS
  6848.  
  6849. =   Equal
  6850. <>  Not Equal
  6851. <   Less Than
  6852. >   Greater Than
  6853. <=  Less Than or Equal To
  6854. >=  Greater Than or Equal To
  6855. NOT Logical "Not"
  6856. AND Logical "And"
  6857. OR  Logical "Or"
  6858.  
  6859. Expressions equals 1 if true, 0 if false.
  6860.  
  6861.  
  6862. SYSTEM COMMANDS
  6863.  
  6864. LOAD "NAME"     Loads a program from tape
  6865. SAVE "NAME"     Saves a program on tape
  6866. LOAD "NAME",8   Loads a program from disk
  6867. SAVE "NAME",8   Saves a program to disk
  6868. VERIFY "NAME"   Verifies that program was SAVEd without errors
  6869. RUN             Executes a program
  6870. RUN xxx         Executes program starting at line xxx
  6871. STOP            Halts execution
  6872. END             Ends execution
  6873. CONT            Continues program execution from line
  6874.                 where program was halted
  6875. PEEK(X)         Returns contents of memory location X
  6876. POKE X,Y        Changes contents of location X to value Y
  6877. SYS xxxxx       Jumps to execute a machine language program,
  6878.                 starting at xxxxx
  6879. WAIT X,Y,Z      Program waits until contents of location X, when EORed
  6880.                 with Z and ANDed with Y, is nonzero.
  6881. USR(X)          Passes value of X to a machine language subroutine
  6882.  
  6883.  
  6884. EDITING AND FORMATTING COMMANDS
  6885.  
  6886. LIST            Lists entire program
  6887. LIST A-B        Lists from line A to line B
  6888. REM Message     Comment message can be listed but is ignored
  6889.                 during program execution
  6890. TAB(X)          Used in PRINT statements. Spaces X positions on screen
  6891. SPC(X)          PRINTs X blanks on line
  6892. POS(X)          Returns current cursor position
  6893.  
  6894. CLR/HOME        Positions cursor to left-up corner of screen
  6895. SHIFT CLR/HOME  Clears screen and places cursor in "Home" position
  6896. SHIFT INS/DEL   Inserts space current cursor position
  6897. INST/DEL        Deletes character at current cursor position
  6898. CTRL            When used with numeric color key, selects text color. May
  6899.                 be used in PRINT statement.
  6900. CRSR Keys       Moves cursor up, down, left right on screen
  6901. Commodore Key   When used with SHIFT selects between upper/lower case and
  6902.                 graphic display mode. When used with numeric key, selects
  6903.                 optional text color
  6904.  
  6905.  
  6906. ARRAYS AND STRINGS
  6907.  
  6908. DIM A(X,Y,Z)    Sets maximum subscripts for A; reserves space for
  6909.                 (X+1)*(Y+1)*(Z+1) elements starting at A(0,0,0)
  6910. LEN(X$)         Returns number of characters in X$
  6911. STR$(X)         Returns numeric value of X, converted to a string
  6912. VAL(X$)         Returns numeric value of X$, up to first nonnumeric
  6913.                 character
  6914. CHR$(X)         Returns ASCII character whose code is X
  6915. ASC(X$)         Returns ASCII code for first character of X$
  6916. LEFT$(A$,X)     Returns leftmost X characters of A$
  6917. RIGHT$(A$,X)    Returns rightmost X characters of A$
  6918. MID$(A$,X,Y)    Returns Y characters of A$ starting at character X
  6919.  
  6920.  
  6921. INPUT/OUTPUT COMMANDS
  6922.  
  6923. INPUT A$ or A   PRINTs '?' on screen and waits for user to enter
  6924.                 a string or value
  6925. INPUT "ABC";A   PRINTs message and waits for user to enter value.
  6926.                 Can also INPUT A$
  6927. GET A$ or A     Waits for user type one-character value;
  6928.                 no RETURN needed
  6929. DATA A,"B",C    Initializes a set of values that can be used by READ
  6930.                 statement
  6931. READ A$ or A    Assigns next DATA value to A$ or A
  6932. RESTORE         Resets data pointer to start READing the DATA list again
  6933. PRINT "A=";A    PRINTs string 'A=' and value of A; ';' suppresses spaces;
  6934.                 ',' tabs data to next field
  6935.  
  6936.  
  6937. PROGRAM FLOW
  6938.  
  6939. GOTO X          Branches to line X
  6940. IF A=3 THEN 10  IF assertion is true THEN execute following part of
  6941.                 statement. IF false, execute next line number
  6942. FOR A=1 to 10   Executes all statements between FOR and corresponding
  6943. STEP 2: NEXT    NEXT, with A, going from 1 to 10 by 2. Step size is 1
  6944.                 unless specified
  6945. NEXT A          Defines end of loop. A is optional
  6946. GOSUB 2000      Branches to subroutine starting at line 2000
  6947. RETURN          Marks end of subroutine. Returns to statement following
  6948.                 most recent GOSUB
  6949. ON X GOTO A,B   Branches to Xth line number on list.
  6950.                 If X=1 branches to A, etc.
  6951. ON X GOSUB A,B  Branches to subroutine at Xth line number in list
  6952.  
  6953.  
  6954.  
  6955. ABOUT THE COMMODORE 64 USERS GUIDE...
  6956.  
  6957. Outstanding   color  ...  sound  synthesis  ...  graphics  ...  computing
  6958. capabilities   ...   the   synergistic   marriage   of   state-of-the-art
  6959. technologies.  These  features  make  the  Commodore 64 the most advanced
  6960. personal computer in its class.
  6961.  
  6962. The Commodore 64 User's Guide helps you get started in computing, even if
  6963. you're   never  used  a  computer  before.  Through  clear,  step-by-step
  6964. instructions,  you  are  given an insight into the BASIC language and how
  6965. the Commodore 64 can be put to a myriad of uses.
  6966.  
  6967. For those already familiar with microcomputers,  the advanced programming
  6968. sections and appendices explain the enhanced features of the Commodore 64
  6969. and how to get the most of these expanded capabilities.
  6970.  
  6971.    _____
  6972.   /  ___|___
  6973.  |  /   |__/  c o m m o d o r e
  6974.  |  \___|__\  C O M P U T E R
  6975.   \_____|
  6976.  
  6977. Commodore Business Machines, Inc. -- Computer Systems Division,
  6978. 487 Devon Park Drive, Wayne, PA 19087.
  6979.  
  6980. DISTRIBUTED BY
  6981. Howard W. Sams & Co., Inc.
  6982. 4300 W. 62nd Street, Indianapolis, Indiana 46268 USA
  6983.  
  6984. $12.95/22010
  6985.  
  6986. ISBN:0-672-22010-5
  6987.  
  6988. *********
  6989.  
  6990. End of the Project 64 etext of the Commodore 64 User's Guide.
  6991.  
  6992. *********
  6993.